Hi,
I store date as 2007-06-01 11:39:04 in db for loggedin users.
Now i am showing the login as last login: 01-06-2007 11:39:04 .
How can i change the db date to the date above i mention as 01-06-2007 11:39:04.
| SitePoint Sponsor |




Hi,
I store date as 2007-06-01 11:39:04 in db for loggedin users.
Now i am showing the login as last login: 01-06-2007 11:39:04 .
How can i change the db date to the date above i mention as 01-06-2007 11:39:04.
From PHP:
Does this help?PHP Code:$datetime = "2007-06-01 11:39:04";
list($date,$time) = split(" ", $datetime);
list($y, $m, $d) = split("-", $date);
echo date('d-m-Y', mktime(0,0,0,$m,$d,$y)) . " " . $time;




Thanks mate.
Its working like a charm.
Its faster if you format it as it comes out of the database by using the date_format functions provided by your database. No need to run that php code every time you need to display a date as well.
If the date in the database isn't stored in an actual datetime field, then you will need to cast it first to a datetime data type before you can use the format function. Either way, its still faster to do it in the db server as part of the sql statement when you extract it. Particularly if you have a lot of them to do.
You can really use Date_Format in your query.




thanks guys for comments yes i know that pulling from db as date_format is faster than any code,
I am thinking to pull out it like this,but i will compare it with that code, which one is realable.




Thanks logic_earth.
I like one line code.
Bookmarks