DomMarx Posted June 13, 2013 Share Posted June 13, 2013 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! Link to comment https://forums.phpfreaks.com/topic/279094-array-for-comment-timestamps/ Share on other sites More sharing options...
Barand Posted June 13, 2013 Share Posted June 13, 2013 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 Link to comment https://forums.phpfreaks.com/topic/279094-array-for-comment-timestamps/#findComment-1435637 Share on other sites More sharing options...
DomMarx Posted June 13, 2013 Author Share Posted June 13, 2013 Thanks Barand i'll try that! Link to comment https://forums.phpfreaks.com/topic/279094-array-for-comment-timestamps/#findComment-1435642 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 Link to comment https://forums.phpfreaks.com/topic/279094-array-for-comment-timestamps/#findComment-1435644 Share on other sites More sharing options...
Barand Posted June 13, 2013 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? Link to comment https://forums.phpfreaks.com/topic/279094-array-for-comment-timestamps/#findComment-1435654 Share on other sites More sharing options...
DomMarx Posted June 13, 2013 Author Share Posted June 13, 2013 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. Link to comment https://forums.phpfreaks.com/topic/279094-array-for-comment-timestamps/#findComment-1435658 Share on other sites More sharing options...
DomMarx Posted June 13, 2013 Author Share Posted June 13, 2013 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! Link to comment https://forums.phpfreaks.com/topic/279094-array-for-comment-timestamps/#findComment-1435661 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. Link to comment https://forums.phpfreaks.com/topic/279094-array-for-comment-timestamps/#findComment-1435704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.