Jump to content

Array for comment timestamps


DomMarx
Go to solution Solved by Barand,

Recommended Posts

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 by DomMarx
Link to comment
Share on other sites

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 by Barand
Link to comment
Share on other sites

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  :happy-04:

Link to comment
Share on other sites

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 by DomMarx
Link to comment
Share on other sites

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 by DomMarx
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.