Reputation: 1929
This is my script that calculates sunrise time for San Jose for today but if I wanted to get it for tomorrow how can I do it?
<?php
//San Jose, CA
$lat = 37.339386; // North
$long = -121.894955; // East
$offset = -8; // difference between GMT and local time in hours
$zenith=90+50/60;
echo "<br><p>Sunrise: ".date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset);
echo "<br>Sunset: ".date_sunset(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset);
?>
Upvotes: 2
Views: 2039
Reputation: 10091
The Linux/GNU Bash command timewarp
executes a given program in a timewarp thread. This mechanism uses special hardware built into most modern CPUs. The timewarp thread is isolated in a specified time, run, and returns the result now.
Here's the syntax:
timewarp --time 86400 "php calculatesunrise.php"
For more information on timework, man timewarp
This basically executes your calculation tomorrow, eliminating the need to change the algorithm. Use exec() to run this. Note, this does not work on a Windows machine. If you need it to work on a Windows machine, use sleep(86400)
instead.
Upvotes: 0
Reputation: 55354
You would need to use the date math functions to add 24 hours to time(). In place of time(), use:
strtotime('+1 day', time());
Upvotes: 1
Reputation: 13542
The PHP function, time()
gives you the current time in seconds since "The Epoch". You can use strtotime()
to do lots of different conversions, including relative conversions.
You can use strtotime()
to get the time 1-day from now:
strtotime("+1 day");
just replace time()
in your code, with strtotime("+1 day")
Upvotes: 8
Reputation: 219077
Just add one day to your calls to the time()
function. If I remember correctly, it takes seconds. So to add a day you'll need to add 60 * 60 * 24
to it.
Upvotes: 1
Reputation: 363
Pass date_sunrise() and date_sunset() the parameter:
time() + (24 * 60 * 60)
For a date 24 hours in the future (ie, tomorrow).
Upvotes: 3