Solved

how to format a date & put in file?

Posted on 2002-04-07
7
224 Views
Last Modified: 2008-03-10
hai,
I have a date format as 27/02/2002 which I need to added to a tmp file & then to mysql db(which accepts only yymmdd format)
my coding as follows

ereg("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", trim($a[5]),$regs // where $a[5] is an array index which stores the date value.

echo "<td>".$regs[3]."-".$regs[2]."-".$regs[1]."</td>";
$a[5] = $regs[3]."-".$regs[2]."-".$regs[1];//here I change to yymmday format

//if I want to add this in to temp file I add foll code
$writetofile5 = fputs($fd,$a[5].",")); //where $fd is tmp file.

I still cannot get my required format in the temp file.
it still exists as 27/02/2002

can anyone suggest how to write in a file my revised format.
thank u




0
Comment
Question by:manju70
  • 4
  • 3
7 Comments
 
LVL 5

Accepted Solution

by:
dkjariwala earned 25 total points
ID: 6924764
You can do without regexp here.

Try this.

$org_date = "27/02/2002";

$date_arr = explode("/",$org_date);
//$date_arr[0] = 27
//$date_arr[1] = 02
//$date_arr[2] = 2002

// So now you can construct date in format you like.

$new_date1= $date_arr[2] . "/" . $date_arr[1] . "/" . $date_arr[0]; //YYYY/MM/DD format in $new_date1.

//$new_date1=2002/02/27

$new_date2 = substr($date_arr[2],2). "/" . $date_arr[1] . "/" . $date_arr[0]; //YY/MM/DD format in $new_date2.

$new_date2 = 02/02/27


Hope that helps,
JD


0
 

Author Comment

by:manju70
ID: 6924792
hai JD,

thanks for ur reply.
but can u tell me how to add it in a tmp file using fputs function.

my coding for the same is as below.

$writetofile5 = fputs($fd,$new_date2.",")); //where $fd is tmp file.

can u check for me.

thanks




 

0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 6924797
Yeah that code is correct.

Provided you have *successfully* opened file having pointer $fd.

JD
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:manju70
ID: 6924929
thank u JD,

It works well.
thank u very much.

c u then if I have any more queries.
bye


0
 
LVL 5

Expert Comment

by:dkjariwala
ID: 6924940
Sure.

Manju, are you indian by any chance ??

JD
0
 

Author Comment

by:manju70
ID: 6927401
yes why????????
0
 

Author Comment

by:manju70
ID: 6927404
yes why????????
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now