Reputation: 27
Okay, so whenever someone presses a button on my website the time gets stored of when the clicked the button, I store this data using date(); and I do not use any format or something.
Now I want to check if 24 hours have passed from when the clicked the button, if they have they can click it again, if they haven't they can't.
I've always used the Java currentTimeMS but I don't think it's the same, so how would I check if 24 hours have passed from the non-formatted date(); stored in my MySQL Database.
Upvotes: 2
Views: 10411
Reputation: 374
$timefromdatabase = 1489834968;
$dif = time() - $timefromdatabase;
if($dif > 86400)
{
echo 'more than 24 hours';
}else{
echo 'less than 24 hours';
}
Upvotes: 11
Reputation: 3863
// your first date coming from a mysql database (date fields)
$dateA = '2013-11-11 23:10:30';
// your second date coming from a mysql database (date fields)
$dateB = '2013-11-11 16:27:21';
$timediff = strtotime($dateA) - strtotime($dateB);
if($timediff > 86400){
echo 'more than 24 hours';
}
else
{
echo 'less than 24 hours';
}
Upvotes: 3