Cliftron Posted September 25, 2009 Share Posted September 25, 2009 Hey another basic question. When i post stuff to my db ,NOW()) it just inserts a unix timestamp (i think its called) when i get the data from the data base how do i translate from unix time stamp to D/M/Y? Link to comment https://forums.phpfreaks.com/topic/175438-solved-php-date-from-sql/ Share on other sites More sharing options...
MadTechie Posted September 25, 2009 Share Posted September 25, 2009 if your doing it via PHP then echo date("d/m/y",$timestamp) but for pure SQL then SELECT DATE_FORMAT(now(),'%e/%m/%y') as formatTime Hope that helps Link to comment https://forums.phpfreaks.com/topic/175438-solved-php-date-from-sql/#findComment-924508 Share on other sites More sharing options...
Cliftron Posted September 25, 2009 Author Share Posted September 25, 2009 so would this be correct when i pull it from the db? $timestamp = $list['Date']; echo date("d/m/y",$timestamp) Link to comment https://forums.phpfreaks.com/topic/175438-solved-php-date-from-sql/#findComment-924514 Share on other sites More sharing options...
MadTechie Posted September 25, 2009 Share Posted September 25, 2009 It really depends on the query, personally i create an alias ie $SQL = "SELECT *, NOW() as theDate FROM table"; $timestamp = $list['theDate']; echo date("d/m/y",$timestamp) but you can also do this $SQL = "SELECT *, DATE_FORMAT(now(),'%e/%m/%y') as theDate FROM table"; echo $list['theDate'] Link to comment https://forums.phpfreaks.com/topic/175438-solved-php-date-from-sql/#findComment-924520 Share on other sites More sharing options...
Cliftron Posted September 25, 2009 Author Share Posted September 25, 2009 when i have $sql = "SELECT *, DATE_FORMAT(now(),'%e/%m/%y') as Date FROM news ORDER BY id DESC LIMIT $offset, $rowsperpage"; echo $list['Date']; it just shows the current date. Link to comment https://forums.phpfreaks.com/topic/175438-solved-php-date-from-sql/#findComment-924531 Share on other sites More sharing options...
Cliftron Posted September 25, 2009 Author Share Posted September 25, 2009 Never mind i fixed it! Thanks for the help Link to comment https://forums.phpfreaks.com/topic/175438-solved-php-date-from-sql/#findComment-924538 Share on other sites More sharing options...
MadTechie Posted September 25, 2009 Share Posted September 25, 2009 , I know you know now, but for others change the now() to the field name of your date Link to comment https://forums.phpfreaks.com/topic/175438-solved-php-date-from-sql/#findComment-924562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.