Link to home
Start Free TrialLog in
Avatar of Alex Lord
Alex Lord

asked on

How to tell if unix timestamp is he 24 hours window of current timestamp,

 $created = date('d-m-Y',$setupCampaigns['TIMESTAMP']);
    

        if($setupCampaigns['TIMESTAMP'] < time() + 86400){
            $new = "<div class='new-eng-alert has-tooltip' data-original-title='null'>1</div>";
        } else {
            $new = "";
        }

Open in new window


how can i tell if this current timestamp is within the 24 hours old from the current timestamp,

if yes display new else dont.

for example if timestamp is 2 hours old from current show, if it is 25 hours dont show.
Avatar of David Favor
David Favor
Flag of United States of America image

Likely you're hitting a precedence problem. Try this code instead...

if ($setupCampaigns['TIMESTAMP'] < (time() + 86400)) {

Open in new window

Hi,

Also make sure you set the default timestamps on your PHP page https://php.net/manual/en/function.time.php
for example
date_default_timezone_set("UTC"); 

Open in new window


otherwise you won't have the correct calculation.

Paid attention to the DB timestamps too as the DB maybe set for another timezone..
You can check that using PHPMyAdmin.

if this is different and your are using Timestamp field you will need to set the timezone in your DB connection script using an offset
something like this  $offset refer to a specific calculation ...
$db->exec("SET time_zone='$offset';");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial