Reputation: 529
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
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
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
Reputation: 522005
if (date('Y-m-d', $timestamp) == date('Y-m-d')) {
// yes, it's the same day
}
Upvotes: 6