A quick read through the date functions in the manual is worthwhile

In particular, you need to look at strtotime() and date().

strtotime() is an often overlooked function, useful for getting almost any
english written date into a unix timestamp, then use date() to get it into
the format you wish.

Note, I removed the commas from the $date string, because I'm pretty sure it
will break the strtotime() function.


$date = "April 11, 2002, 1:53 pm";

// one step at a time
$date = str_replace(",","",$date);
$date = strtotime($date);
$date = date('Y-m-d', $date);

// or, in one line, if that's your thing
$date = date('Y-m-d', strtotime(str_replace(",","",$date)));


Alternatively, you could have split the date on commas, and mucked around
with each element, but the above, IMHO, is the best way to go.


Justin French
Creative Director

on 22/04/02 10:10 PM, hamish ([EMAIL PROTECTED]) wrote:

> Hello All,
> I have a variable in the following date format:
> April 11, 2002, 1:53 pm
> and want to get it to the following format:
> yyyy-mm-dd 
> what's the best way?
> hamish

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to