Reputation: 311
Here is my table. dateline column is in hours.
How can I print time remaining in hours based on dateline, created_at and current time?
Upvotes: 1
Views: 232
Reputation: 49208
You can use strtotime()
:
<?php
$created = 1323504315;
$timeleft = 144;
$expires = strtotime("+$timeleft hours", $created);
$compare_text = "created: " . date('m/d/Y H:i A',$created) . ", now: " . date('m/d/Y H:i A') . " > expires:" . date('m/d/Y H:i A',$expires);
if (mktime() > $expires) {
echo "The time has expired. ($timeleft, $compare_text)";
} else {
echo "The time has not expired. ($timeleft, $compare_text)";
}
?>
Upvotes: 1
Reputation: 100195
$hours = "144"; //from dataline $totalHours = date("H") - $hours; $totalMinutes = date("i"); $totalSeconds = date("s"); $totalMonths = date("m"); $totalDays = date("d"); $totalYears = date("Y"); $timeStamp = mktime($totalHours, $totalMinutes, $totalSeconds, $totalMonths, $totalDays, $totalYears); $myTime = date("H:i A", $timeStamp);
Upvotes: 0