mikeroq Posted March 18, 2006 Share Posted March 18, 2006 Im trying to make a today and yesterday function for unix time stamps, i did one but i made it very wrong, it works, it just doesnt work right.I though of taking off 84600 or 86400 w/e it is, but then that presents a problem cause then it would be a rolling date, i need a function that will do this.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/5210-today-and-yesterday/ Share on other sites More sharing options...
kenrbnsn Posted March 18, 2006 Share Posted March 18, 2006 You might want to look at the strtotime() function:[code]<?php$today = strtotime('today');$yesterday = strtotime('yesterday');echo '$today = ' . $today . '<br>$yesterday = ' . $yesterday;?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/5210-today-and-yesterday/#findComment-18499 Share on other sites More sharing options...
mikeroq Posted March 18, 2006 Author Share Posted March 18, 2006 Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/5210-today-and-yesterday/#findComment-18524 Share on other sites More sharing options...
mikeroq Posted March 26, 2006 Author Share Posted March 26, 2006 ok this no longer works, this is my code[code]function nixtime($unix) { if ($unix == "1129679173") { return "Never"; } else { $unix = $unix; $today = strtotime("today"); $yesterday = strtotime("yesterday"); $two = strtotime("2 days ago"); if ($unix < $today && $unix > $yesterday) { $visit = date('g:i a', $unix ); return "Today, $visit"; } if ($unix > $two && $unix < $yesterday) { $visit = date('g:i a', $unix ); return "Yesterday, $visit"; } else { $visit = date('n/j/y g:i a', $unix ); return $visit; } } }[/code][a href=\"http://mikeroq.be/?x=forum\" target=\"_blank\"]http://mikeroq.be/?x=forum[/a]or anywhere else, it willl say yesterday for today, and today for yesterday and show incorrect times like today at 6:30am when its only 4:30am server time Quote Link to comment https://forums.phpfreaks.com/topic/5210-today-and-yesterday/#findComment-20808 Share on other sites More sharing options...
Barand Posted March 26, 2006 Share Posted March 26, 2006 You are defining today as any time in the last 24 hours and not as times since midnight.Try[code]function nixtime($unix) { if ($unix == "1129679173") { return "Never"; } else { $today = mktime(0,0,0, date('m'), date('d'), date('Y')); $yesterday = mktime(0,0,0, date('m'), date('d')-1, date('Y')); if ($unix > $today) { $visit = date('g:i a', $unix ); return "Today, $visit"; } elseif ($unix > $yesterday && $unix < $today) { $visit = date('g:i a', $unix ); return "Yesterday, $visit"; } else { $visit = date('n/j/y g:i a', $unix ); return $visit; } } }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5210-today-and-yesterday/#findComment-20813 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.