Jump to content

Changing a UNIX timestamp into "Today" and "Yesterday"


CMellor

Recommended Posts

Odd as this may sound, I have only just discovered the [b]strtotime()[/b] function. I like the looks of what it is capable of and have tried to use it to my advantage. I tried to make a little script that would convert a UNIX time stamp into a message saying whether or not the stamp was a time for today, or yesterday, or if neither, then just display the date it is.

I'm not a PHP pro, but am always learning. I have looked all over for tutorials on how to do this, but the only useful one's I found are for blogging software. I was hoping someone here could guide me in the right direction of where to begin coding this script, or maybe provide me with a sample that I can toy around with myself. Any help at all would be appreciated.

Thanks for reading,

Chris.
Link to comment
Share on other sites

Well, once you've got a UNIX timestamp, you can use the date() function to parse out the year, month and day of the timestamp. Just check to see whether this date is equivalent to yesterday or today and execute accordingly:
[code]
<?php
if (date('Y-m-d', $timestamp) == date('Y-m-d')) {
  // The timestamp is from today!
} elseif (date('Y-m-d', $timestampe) == date('Y-m-d', strtotime("Yesterday"))) {
  // The timestamp is from yesterday!
} else {
  // The timestamp is from neither today nor yesterday!
}
?>
[/code]
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.