|
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]
|