Solved

how to format a date & put in file?

Posted on 2002-04-07
7
221 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
Comment Utility
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
Comment Utility
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
Comment Utility
Yeah that code is correct.

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

JD
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:manju70
Comment Utility
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
Comment Utility
Sure.

Manju, are you indian by any chance ??

JD
0
 

Author Comment

by:manju70
Comment Utility
yes why????????
0
 

Author Comment

by:manju70
Comment Utility
yes why????????
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

772 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

15 Experts available now in Live!

Get 1:1 Help Now