Skip to main content.

Sunrise - Sunset PHP Script by Mike Challis

This script uses built-in PHP 5 functions (date_sunrise and date_sunset) to calculate sunrise - sunset times and determine if it is currently day or night time. PHP version 5.1.3 or higher is required.

What does it do?
This script automatically generates sunrise - sunset times. Here is a demo: sunrise-sunset.php. I use this script to hide the volcano cam at night and tell my visitors what time the sunrise will occur. I also use it to turn off my web cam history archives at night time.

Why use it?
To print the sunrise - sunset times for your location. And determine if it is currently night or day. It can easily be modified to be used as a switch to activate PHP code for day or night time only use.

How use it?
Just download the file, adjust a few settings at the top, upload it to your web server, and call it as an include file from PHP code in your web page. Please refer to the readme.txt in the download for all the details.

Sunrise - Sunset PHP Script: [download it] | [Discuss it]

More Weather PHP Scripts


If you find this site or the free PHP scripts useful to you, please consider making a small donation to help offset my time and the routine expenses of operation of this website. Thanks for your kind support! - Mike Challis

This php code provided "as is," and Long Beach Weather (Michael Challis) disclaims any and all warranties, whether express or implied, including (without limitation) any implied warranties of merchantability or fitness for a particular purpose. Use of this code signifies your acceptance.