spires Posted October 3, 2006 Share Posted October 3, 2006 Hi, I have submitted the date into my database using:[code]$date = date("Y-m-d > H:i:s");[/code]Now my customer wants the date to read:[code]$date = date("d-m-Y > H:i:s");[/code]how can i change this when pulling the data out of the database?Can this be done, or does it have to be before?Thanks for all your help. Link to comment https://forums.phpfreaks.com/topic/22886-date-shoud-be-a-quick-question/ Share on other sites More sharing options...
shivabharat Posted October 3, 2006 Share Posted October 3, 2006 Hi, If you are using MySQL refer DATE_FORMAT(date,format) function. Link to comment https://forums.phpfreaks.com/topic/22886-date-shoud-be-a-quick-question/#findComment-103165 Share on other sites More sharing options...
spires Posted October 3, 2006 Author Share Posted October 3, 2006 ok, thanks i'll try it. Link to comment https://forums.phpfreaks.com/topic/22886-date-shoud-be-a-quick-question/#findComment-103169 Share on other sites More sharing options...
sasa Posted October 3, 2006 Share Posted October 3, 2006 is this help [code]<?phpfunction change_date_format($date) { $date = explode(' > ',$date); return implode('-',array_reverse(explode('-',$date[0]))).' > '.$date[1];}$date = date("Y-m-d > H:i:s");echo change_date_format($date)."<br />\n";?>[/code] Link to comment https://forums.phpfreaks.com/topic/22886-date-shoud-be-a-quick-question/#findComment-103231 Share on other sites More sharing options...
Daniel0 Posted October 3, 2006 Share Posted October 3, 2006 [quote author=shivabharat link=topic=110385.msg446098#msg446098 date=1159893099]Hi, If you are using MySQL refer DATE_FORMAT(date,format) function. [/quote]I would suggest to store a UNIX timestamp instead, that makes it easier to sort dates, format it different formats using date() etc. Link to comment https://forums.phpfreaks.com/topic/22886-date-shoud-be-a-quick-question/#findComment-103245 Share on other sites More sharing options...
obsidian Posted October 3, 2006 Share Posted October 3, 2006 [quote author=Daniel0 link=topic=110385.msg446178#msg446178 date=1159899734]I would suggest to store a UNIX timestamp instead, that makes it easier to sort dates, format it different formats using date() etc.[/quote]definitely the best practice, but if you can't, you could just use this to print it after you take it out:[code]<?php$date = date('Y-m-d > H:i:s');list($date, $time) = explode(" > ", $date);$new = date('d-m-Y > H:i:s', strtotime("$date $time"));echo $new;?>[/code] Link to comment https://forums.phpfreaks.com/topic/22886-date-shoud-be-a-quick-question/#findComment-103254 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.