|
Posted by Toby A Inkster on 11/13/07 17:47
ZeldorBlat wrote:
> Use strtotime() and date():
> date('Y-m-d', strtotime($dateandtime));
If you know that DMY dates are more likely than MDY dates, strtotime() can
be problematic. In the case of an ambiguous date (e.g. 01/02/08) it will
always assume MDY, which will be wrong in the majority of cases (less than
10% of the world uses MDY dates).
I recommend taking a look at my strtotime_i18n() function which takes two
parameters: the date string, plus a hint of the form 'dmy', 'mdy' or
'ymd':
http://demiblog.svn.sourceforge.net/viewvc/demiblog/trunk/blog/includes/i18n.php?view=markup
Something like '01/28/2008' will always be parsed as 28 Jan 2008 as there
is no 28th month, but in ambiguous cases, it should help you out. If you
want to use it, you may want to rewrite the small part at the top of the
function which checks if $assumption==NULL. It relies on some other
functions and objects in my project, which you're less likely to want to
use.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 7 days, 26 min.]
TrivialEncoder/0.2
http://tobyinkster.co.uk/blog/2007/08/19/trivial-encoder/
[Back to original message]
|