Welcome to WebmasterWorld Guest from 54.162.239.134

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How to format date

from YYYY-MM-DD to DD/MM/YYY and vice versa

     
7:02 am on Oct 11, 2008 (gmt 0)

5+ Year Member



Hi,

How do I format date that will work on both PHP 4 and 5. I want to format date from from YYYY-MM-DD to DD/MM/YYY and vice versa. Is there a built-in function?

Thanks

7:26 am on Oct 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



apply strtotime() to your date in this format YYYY-MM-DD and then send the strtotime() generated unixTimestamp to date() with your new format
9:58 am on Oct 11, 2008 (gmt 0)

5+ Year Member



Thanks...it worked.
10:02 am on Oct 11, 2008 (gmt 0)

5+ Year Member



On a related note when I run the following code it is treating "05" as month when in fact it's a day...any idea how to fix it

$dt = "05/01/2008";
print date("Y-m-d", strtotime($dt));

OUTPUT is 2008-05-01

The date in $dt is in format d/m/Y

10:08 am on Oct 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[php.net...]

The first User Contributed Note from top addresses that issue.

[edited by: Anyango at 10:09 am (utc) on Oct. 11, 2008]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month