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? Quote 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 Quote 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) Quote 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'] Quote 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. Quote 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 Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.