Jump to content

Using the date function to print 'today at x time' - Please help!!


skard

Recommended Posts

Hi. I'm not a programmer, so i hope it doesnt seem rude my asking for help here. Is it allowed? I run a site built in php and often can't get hold of a programmer so try and change little bits myself, usually by finding other bits of code around my site that do a similiar job, and then copying and modifying them.

Something i've been trying to do, but I'm completely lost with it, is this:

 

I have a forum, and on the latest posts page it looks something like this -

 

Last Post:

14th February 2008 16:02

by John Doe

 

Now the code that prints the date part (14th Febuary 2008 16:02) is the following:

 

$content .= $tmp->LastPost->DateFormatted;

 

I'm trying to get it to not just print the date, but if the post was made yesterday, then print:

 

Last Post:

Yesterday at 16:02

by John Doe

 

or if it was made today, then:

 

Last Post:

Today at 16:02

by John Doe

 

A friend of mine changed it to this: $content .= ((mktime() - $tmp->LastPost->Date < 86400) ? 'Today' : $tmp->LastPost->DateFormatted);

Which works to some degree as the final output is this: Last Post: Today by John Doe

but it doesnt show the time the post was made, and its not actually 'today' but in the last 24 hours, which isnt what i want.

 

Can anyone help? Much appreciated if someone can  :) Thanks in advance for any help

 

 

 

 

 

 

 

 

 

 

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.