brad Posted March 12, 2007 Share Posted March 12, 2007 i have a site for my band and i'm ripping off facebook's mini feed idea. i am proficient in PHP, but i just can't get my head around one thing. i have a class with a function called "printBreadTrail" and every time someone updates their profile, joins, comments on a post, comments on a picture etc this breadTrail class i have written logs the time and action as shown in the screenshot below: this is the code as it is now, and then i'll explain what i want some help with: $id = $r["id"]; $user = $r["userid"]; $did = $r["action"]; $what = $r["article"]; $time = $r["time"]; $now = time(); $bT = "<a href='/members/" . $user . "/'>"; $bT .= $user; $bT .= "</a> "; $bT .= $did . " "; $difference = $now - $time; if ($difference >= "84600") { $bT .= "<p class='small'>" . date("D jS, g:ia",$time) . "</p><br>"; } else { $bT .= "<p class='small'>" . date("g:ia",$time) . "</p><br>"; } echo $bT; } currently, if the action happened within the last 24 hours (the 84600 bit) it just shows the time. if it's more than that, it will say that days name and also show the time. i want this: 1) if it happened like 3 days ago i want the Day, Day Number, Month and time like Fri 9th Mar, 10:25am (i can code this date format no problem) 2) if it happened WITHIN the last 24 hours but before midnight, i want it to say "Yesterday, 11:55pm" 3) if it happened WITHIN the last 24 hours but after midnight, i want it to just say the time. does this make sense? if not, basically i want to make it so these two: angelica updated their profile6:50pm brad updated their profile4:22pm would say "yesterday". (within 24hrs but before midnight) i'm sure this will be easyyy for some of you guys thanks for any help you can give me. Link to comment https://forums.phpfreaks.com/topic/42291-solved-need-help-with-time-since-a-unix-timestamp-saying-yesterday-after-midnight/ Share on other sites More sharing options...
brad Posted March 12, 2007 Author Share Posted March 12, 2007 bump! someone must be good enough Link to comment https://forums.phpfreaks.com/topic/42291-solved-need-help-with-time-since-a-unix-timestamp-saying-yesterday-after-midnight/#findComment-205377 Share on other sites More sharing options...
brad Posted March 13, 2007 Author Share Posted March 13, 2007 just one more bump! Link to comment https://forums.phpfreaks.com/topic/42291-solved-need-help-with-time-since-a-unix-timestamp-saying-yesterday-after-midnight/#findComment-205842 Share on other sites More sharing options...
brad Posted March 14, 2007 Author Share Posted March 14, 2007 can't believe such worse coding and queries get lots of help but a nice intriguing one like this gets none love you all readyy! Link to comment https://forums.phpfreaks.com/topic/42291-solved-need-help-with-time-since-a-unix-timestamp-saying-yesterday-after-midnight/#findComment-206716 Share on other sites More sharing options...
kenrbnsn Posted March 14, 2007 Share Posted March 14, 2007 There are 86,400 seconds in a day. So, if "now" - "registration date/time" is less than 86,400, we fall into the "yesterday" time frame. Now we can look at the hour of the registration in 24 hour format. If the hour is greater than the "now" hour, it's before midnight, if it's less than or equal it's after midnight. Translating the above into PHP: <?php $registration_date_time = '3/12/2007 10:00 pm'; // sample for testing $now = time(); //UNIX timestamp of the current date/time $regDate = strtotime($registration_date_time); // UNIX timestamp for the registration date/time $secs_diff = $now - $regDate; if ($secs_diff > 86400) echo date('l, jS F g:i a',$regDate); else { $checkHour = date('G',$regDate); $nowHour = date('G',$now); if ($checkHour > $nowHour) echo 'Yesterday at '. date('g:i a',$regDate); else echo date('g:i a',$regDate); } ?> Ken Link to comment https://forums.phpfreaks.com/topic/42291-solved-need-help-with-time-since-a-unix-timestamp-saying-yesterday-after-midnight/#findComment-206742 Share on other sites More sharing options...
brad Posted March 14, 2007 Author Share Posted March 14, 2007 that is completely amazing. thankyouuu! Link to comment https://forums.phpfreaks.com/topic/42291-solved-need-help-with-time-since-a-unix-timestamp-saying-yesterday-after-midnight/#findComment-206743 Share on other sites More sharing options...
brad Posted March 14, 2007 Author Share Posted March 14, 2007 works perfect. thanks Ken. Link to comment https://forums.phpfreaks.com/topic/42291-solved-need-help-with-time-since-a-unix-timestamp-saying-yesterday-after-midnight/#findComment-206747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.