Formatting Date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bulsecoip
Forum Newbie
Posts: 6
Joined: Thu Jun 26, 2008 12:37 am

Formatting Date

Post by bulsecoip »

Hi, im a newbie in PHP. How can i format a date with a value of '01/31/2008' to become '2008-01-31'?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Formatting Date

Post by califdon »

bulsecoip wrote:Hi, im a newbie in PHP. How can i format a date with a value of '01/31/2008' to become '2008-01-31'?
Where is the '01/31/2008' coming from? A MySQL query? A user form? It makes a difference, because if it's coming from a query, that's just the default format, it's actually stored as a huge number, so you can format it right in the query. If it's coming from a user input, as text, you will have to parse the string to get the values for year, month and day, then use mktime() to generate the actual date (huge number), then use date() to format it the way you want it. Click on those blue links to read how to do it.
bulsecoip
Forum Newbie
Posts: 6
Joined: Thu Jun 26, 2008 12:37 am

Re: Formatting Date

Post by bulsecoip »

thank you very much for the help califdon :mrgreen:
Post Reply