PHP - Time Remaining Until Specific Time from Current Time of Page Load

php - Time remaining until specific time from current time of page load

I'd use the DateInterval and DateTime functions:

$now = new DateTime();
$future_date = new DateTime('2011-05-11 12:00:00');

$interval = $future_date->diff($now);

echo $interval->format("%a days, %h hours, %i minutes, %s seconds");

You'll need a version of PHP that's at least 5.3 to do it this way - otherwise, do what helloandre recommends.

Display Days/Hours Until Certain Time

You can use the relative time format next Sunday 17:00. Like this:

$now = new DateTime();
$future_date = new DateTime('next Sunday 17:00');
$interval = $future_date->diff($now);
echo $interval->format("%d days, %h hours, %i minutes, %s seconds");

Output:

6 days, 2 hours, 33 minutes, 53 seconds

Read more about relative time formats here: http://www.php.net/manual/en/datetime.formats.relative.php

Get different time to end of the current day

Hope this will help you out..

Try this code snippet here


echo remainingTime();
function remainingTime()
{
$string="";
$date= date("Y-m-d H:i:s");
$endDate= date("Y-m-d")." 23:59:59";
$remainingSeconds=strtotime($endDate)-strtotime($date);
$string.=gmdate("H", $remainingSeconds)." hours ";
$string.=gmdate("i", $remainingSeconds)." minutes ";
$string.=gmdate("s", $remainingSeconds)." seconds to the end of current day";
return $string;
}

How to make time left until closing in PHP

Using the time(), mktime(), and gmdate() functions in PHP you can statically return how many hours and minutes are left before a specified time of day.

Note: When using time and date functions, the time returned is the server's system time, which could vary from your local time. You may need to use date_default_timezone_set() if you're server is located in a different timezone.

<?php

// change your default timezone
date_default_timezone_set('America/Chicago');

// get current time of day in unix timestamp
$currentTime = time();

// get closing time in unix timestamp
$closingTime = mktime(16,0,0); // 4pm

// check if the current time is past closing time
if($currentTime > $closingTime)
{
// current time is greater than the closing time
// output closed message
echo "We are curently closed.";
}
else
{
// current time is less than closing time
// get hours and minutes left until closing time
$hoursLeft = gmdate("G", $closingTime - $currentTime);
$minutesLeft = gmdate("i", $closingTime - $currentTime);

// output time left before close
echo $hoursLeft . " hours " . $minutesLeft . " minutes until closing.";
}

?>

Here we get the current time and define when closing time is. We then see if the current time is greater than closing time. If the current time is greater, then we output the closed message. Otherwise, we can use gmdate() to get the hours and minutes remaining based on the difference between closing time and the current time.

Open page at specific time

You'd better use .htaccess directives. The idea is described here http://www.blog.highub.com/apache/http-server/htaccess-deny-diractory-access-during-a-specific-time/

How to get time difference in minutes in PHP

Subtract the past most one from the future most one and divide by 60.

Times are done in Unix format so they're just a big number showing the number of seconds from January 1, 1970, 00:00:00 GMT

Current time + 12 hours

Your database looks to be using GMT, you can change the timezone on the database, but that can be difficult on a production machine if other things are using it. It should fix the problem tho. Or, try this

$date = date( 'Y-m-d H:i:s', strtotime( 'now +12 hours' ) );
$sql = "UPDATE auths SET nextVote = '{$date}' WHERE voter_ip = :ip";

if you want to update your timezone ( and are on ubuntu ), run dkpg-reconfigure tzdata



Related Topics



Leave a reply



Submit