Reply to Re: Converting dd/mm/yyyy to YYYY-MM-DD?

Your name:

Reply:


Posted by ZeldorBlat on 01/11/07 04:02

Vincent Delporte wrote:
> On Thu, 11 Jan 2007 02:42:55 +0100, Vincent Delporte
> <justask@acme.com> wrote:
> >Do I need to call another function in addition to strtotime() to make
> >this happen?
>
> For those interested, I found the following code that seems to work:
>
> $mydate = $_POST["mydate"];
>
> //Date formated as dd/mm/yyyy
> list($d, $m, $y) = preg_split('/\//', $mydate);
>
> $mydate = sprintf('%4d%02d%02d', $y, $m, $d);
> print $mydate;
>
> There may be a better way, such as telling PHP that the dates are
> formatted as dd/mm/yyyy instead of mm/dd/yyyy so that strtotime will
> work without the above kung-fu, but I don't know.

I prefer to keep datetime values as timestamps until the last possible
moment when I format them for display. So you could do something like
this:

$query = "SELECT name, UNIX_TIMESTAMP(mydate) FROM mytable";
//get the value from the query result. It's already a timestamp, so we
don't need strtotime
$my_ts = ... ;
$mydate = date('m/d/Y', $my_ts); //date() does all sorts of nifty stuff

[Back to original 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

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