user1551482
user1551482

Reputation: 529

dealing with unix timestamps in php?

Say for example i had a unix timestamp 1345810244 , what i wanted to do is have a function to check whether this timestamp has the same date as today i.e.

function isToday($unixTimestamp) {

   if ($unixTimestamp == (today){
      return true;
   else
      return false;

}

Im so new to dealing unix timestamps, thanks.

Upvotes: 0

Views: 96

Answers (3)

amitchhajer
amitchhajer

Reputation: 12830

Date and time from unix timestamp

$timestamp = "1340892242";
    $date = date('Y-m-d', $timestamp);
    $time = date("H:i:s", $timestamp);
    echo $date;
    echo $time;

Upvotes: 0

N.B.
N.B.

Reputation: 14060

If you want to do it without DateTime functions, the easiest way (probably not the most accurate, due to missing time zone offsets) would be:

function isToday($unixTimestamp)
{
    return date('d.m.Y', $unixTimestamp) === date('d.m.Y');
}

Upvotes: 0

deceze
deceze

Reputation: 522005

if (date('Y-m-d', $timestamp) == date('Y-m-d')) {
    // yes, it's the same day
}

Upvotes: 6

Related Questions