i need to make a date difference if token had +1 day of being added to database it expires , but the problem i don't know how to calculate the date difference between the date of token adding and the "now" date to check if it's expired or not. I heard about date_diff .. but idk how to use it.
for your accurate need you can just compare two dates.
$now = new DateTime("now");
$now->modify("-1day");
$yourTokenDate = new DateTime($dateFromeDatabase);
if($yourTokenDate > $now){
echo "ok";
}else{
echo "expired";
}
SELECT yourtocken FROM yourtable
WHERE tocken_date > DATESUB("1DAY",NOW())
http://www.php.net/manual/en/datetime.diff.php
Straightforward example from the given link:
Example #1 DateTime::diff() example
Object oriented style
<?php
$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');
?>
Procedural style
<?php
$datetime1 = date_create('2009-10-11');
$datetime2 = date_create('2009-10-13');
$interval = date_diff($datetime1, $datetime2);
echo $interval->format('%R%a days');
?>