DomMarx Posted June 13, 2013 Share Posted June 13, 2013 (edited) Hey guys, I was just wondering if anyone on here has some guidance for someone trying to build a comment time stamp (30 seconds ago, 1 minute ago, 1 month ago, 1 year ago, etc.) that takes the different day count of every month + leap year into consideration. I'm not asking for you guys to give me straight code or anything. I just need some guidance on finding the proper/best method of going about this. I'm guessing placing everything in arrays is a must? Thanks! Edited June 13, 2013 by DomMarx Quote Link to comment Share on other sites More sharing options...
Barand Posted June 13, 2013 Share Posted June 13, 2013 (edited) Use DateTime and DateInterval objects. $timestamp = '2013-06-13 01:00:00'; $dt = new DateTime($timestamp); $diff = $dt->diff(new DateTime())->format('%y,%m,%d,%h,%i,%s'); list ($y, $m, $d, $h, $n, $s) = explode(',', $diff); edit: result $diff = 0,0,0,0,39,5 Edited June 13, 2013 by Barand Quote Link to comment Share on other sites More sharing options...
DomMarx Posted June 13, 2013 Author Share Posted June 13, 2013 Thanks Barand i'll try that! Quote Link to comment Share on other sites More sharing options...
DomMarx Posted June 13, 2013 Author Share Posted June 13, 2013 I also thought i'd ask a quick side question if you don't mind, since you seem pretty knowledgable(being a guru and all haha). When it comes to scalability, does this type of code need to be written differently? Let's say 50,000 users were posting on the website and this type of code was a function to display the comment timestamp, would it eventually break down if it isn't written in a special way? Or does scalability only apply to much larger functions? Just wondering Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted June 13, 2013 Solution Share Posted June 13, 2013 You only need call the function for displayed comments - You aren't planning on displaying 50.000 at a time, are you? Quote Link to comment Share on other sites More sharing options...
DomMarx Posted June 13, 2013 Author Share Posted June 13, 2013 (edited) Probably not 50,000 at a time no haha. I meant more along the lines of having 50,000 members and the odds of a group of them (maybe 2,500 users) coincidently posting comments at once/sharing something at the same time. Edited June 13, 2013 by DomMarx Quote Link to comment Share on other sites More sharing options...
DomMarx Posted June 13, 2013 Author Share Posted June 13, 2013 (edited) I tried the following to experiment, but the Seconds just start over at 0 when reaching 60. Could anyone tell me what is wrong here? <?php $actual_time = date('s'); echo $actual_time." ".'Seconds ago '; if ($actual_time >= 60){ $actual_time = strtotime("+ 1 minute"); echo $actual_time." ".'Minutes ago '; } ?> Also, thanks again for taking the time Barand. This forum is great! Edited June 13, 2013 by DomMarx Quote Link to comment Share on other sites More sharing options...
Barand Posted June 13, 2013 Share Posted June 13, 2013 dates('s') has a value range of 0 - 59. It is the seconds element of the time display. Quote Link to comment 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.