Page 1 of 1

Formatting Date

Posted: Mon Jul 07, 2008 9:23 pm
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'?

Re: Formatting Date

Posted: Mon Jul 07, 2008 9:49 pm
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.

Re: Formatting Date

Posted: Tue Jul 08, 2008 2:54 am
by bulsecoip
thank you very much for the help califdon :mrgreen: