Jump to content

Recommended Posts

I've noticed alot of sites convert certain dates, especially for comments into a format like "x day y hr z min ago".

It seems pretty neat.

I have a date that I store in mysql, type is datetime, so the format is:

2008-11-12 12:30:02

Is there like a standard way to convert this?

 

Thanks

 

btw I think someone in the user comments of date submitted a function that pretty much does what you're wanting.  Might want to read through it, save you the trouble.

 

Great, I will definitely read through that.  Thanks for the info.

Here's the code....

function ezDate($d) {
$ts = time() - strtotime(str_replace("-","/",$d));
    if($ts>31536000) $val = round($ts/31536000,0).' year';
    else if($ts>2419200) $val = round($ts/2419200,0).' month';
    else if($ts>604800) $val = round($ts/604800,0).' week';
    else if($ts>86400) $val = round($ts/86400,0).' day';
    else if($ts>3600) $val = round($ts/3600,0).' hour';
    else if($ts>60) $val = round($ts/60,0).' minute';
    else $val = $ts.' second';
    if($val>1) $val .= 's';
    return $val;
    }

    $newCommentDate = ucwords(ezDate($commentDate)).' Ago';

 

Worked like a charm!.....actually, it was less code than I thought it might take....

Awesome!....

Sometimes, I feel ike a jackace copying digg on alot of their things, but, if your going to get influence or copy, might as well copy someone who's really good.

 

Thanks again...

 

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.