homepage Welcome to WebmasterWorld Guest from 54.211.97.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How to format date
from YYYY-MM-DD to DD/MM/YYY and vice versa
TechMan

5+ Year Member



 
Msg#: 3763475 posted 7:02 am on Oct 11, 2008 (gmt 0)

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

 

Anyango

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3763475 posted 7:26 am on Oct 11, 2008 (gmt 0)

apply strtotime() to your date in this format YYYY-MM-DD and then send the strtotime() generated unixTimestamp to date() with your new format

TechMan

5+ Year Member



 
Msg#: 3763475 posted 9:58 am on Oct 11, 2008 (gmt 0)

Thanks...it worked.

TechMan

5+ Year Member



 
Msg#: 3763475 posted 10:02 am on Oct 11, 2008 (gmt 0)

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

Anyango

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3763475 posted 10:08 am on Oct 11, 2008 (gmt 0)

[php.net...]

The first User Contributed Note from top addresses that issue.

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved