You are here: Re: formmating dates? « PHP Programming Language « IT news, forums, messages
Re: formmating dates?

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/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация