W3Schools.com

PHP date_sunrise() Function


PHP Date Reference Complete PHP Date Reference

Definition and Usage

The date_sunrise() function returns the time of sunrise for a specified day and location.

Syntax

date_sunrise(timestamp,format,latitude,longitude,zenith,gmt_offset)

Parameter Description
timestamp Required.
format

Optional. Specifies how to return the result:

  • SUNFUNCS_RET_STRING (returns the result as string. e.g. 16:46)
  • SUNFUNCS_RET_DOUBLE (returns the result as float. e.g. 16.78243132)
  • SUNFUNCS_RET_TIMESTAMP (returns the result as integer (timestamp). e.g. 1095034606)
latitude

Optional. Specifies the latitude of the location. The latitude defaults to North. If you want to specify a South value, you must pass a negative value.

longitude

Optional. Specifies the longitude of the location. The longitude defaults to East. If you want to specify a West value, you must pass a negative value.

zenith Optional.
gmt_offset

Optional. Specifies the difference between GMT and local time in hours.



Example

<?php
//Calculate the sunrise time for Lisbon, Portugal
//Latitude: 38.4 North
//Longitude: 9 West
//Zenith ~= 90
//offset: +1 GMT
echo("Date: " . date("D M d Y") . "<br />");
echo("Sunrise time: ");
echo(date_sunrise(time(),SUNFUNCS_RET_STRING,38.4,-9,90,1));
?>

The output of the code above could be:

Date: Tue Jan 24 2006
Sunrise time: 08:52


PHP Date Reference Complete PHP Date Reference
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE