Solved

how to format a date & put in file?

Posted on 2002-04-07
7
235 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

696 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