PHP date_sunrise() Function

In this chapter you will learn:

  1. Definition for PHP date_sunrise() Function
  2. Syntax for PHP date_sunrise() Function
  3. Parameter for PHP date_sunrise() Function
  4. Return value from PHP date_sunrise() Function
  5. Example - Return the sunrise time for Lisbon, Portugal today

Definition

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

date_sunset() function returns the sunset time for a specified day and location.

Syntax

PHP date_sunrise() Function has the following syntax.

date_sunrise(timestamp,format,latitude,longitude,zenith,gmtoffset);

Parameter

ParameterIs RequiredDescription
timestampRequired.timestamp of the day from which the sunrise time is taken
formatOptional.returned value format
latitudeOptional.Latitude of the location. Defaults to North. To specify a value for South, pass in a negative value
longitudeOptional.Longitude of the location. Defaults to East. To specify a value for West, pass in a negative value
zenithOptional.Defaults to date.sunrise_zenith
gmtoffsetOptional.Difference between GMT and local time in hours

Format available values.

ValueDescription
SUNFUNCS_RET_STRINGreturns the result as string. e.g. 15:46) (This is default)
SUNFUNCS_RET_DOUBLEreturns the result as float. e.g. 12.123456)
SUNFUNCS_RET_TIMESTAMPreturns the result as integer (timestamp). e.g. 1211233211)

Return

PHP date_sunrise() Function returns the time of the sunrise, in the specified format, on success. FALSE on failure.

Example

Return the sunrise time for Lisbon, Portugal today:


<?php//from ja  v a  2 s  .co  m
echo("Lisbon, Portugal: Date: " . date("D M d Y"));
echo("Sunrise time: ");
echo(date_sunrise(time(),SUNFUNCS_RET_STRING,18.1,-9,80,1));
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP date_sunset() Function
  2. Syntax for PHP date_sunset() Function
  3. Parameter for PHP date_sunset() Function
  4. Return value from PHP date_sunset() Function
  5. Example - Return the sunset time for Lisbon, Portugal today
Home » PHP Tutorial » PHP Date Functions
PHP checkdate() Function
PHP date() Function
PHP date_add() Function
PHP date_create() Function
PHP date_create_from_format() Function
PHP date_date_set() Function
PHP date_default_timezone_get() Function
PHP date_default_timezone_set() Function
PHP date_diff() Function
PHP date_format() Function
PHP date_get_last_errors() Function
PHP date_interval_format() Function
PHP date_isodate_set() Function
PHP date_modify() Function
PHP date_offset_get() Function
PHP date_parse() Function
PHP date_parse_from_format() Function
PHP date_sub() Function
PHP date_sun_info() Function
PHP date_sunrise() Function
PHP date_sunset() Function
PHP date_time_set() Function
PHP date_timestamp_get() Function
PHP date_timestamp_set() Function
PHP date_timezone_get() Function
PHP date_timezone_set() Function
PHP getdate() Function
PHP gettimeofday() Function
PHP gmdate() Function
PHP gmmktime() Function
PHP gmstrftime() Function
PHP idate() Function
PHP localtime() Function
PHP microtime() Function
PHP mktime() Function
PHP strftime() Function
PHP strptime() Function
PHP strtotime() Function
PHP time() Function
PHP Timezones Constant
PHP timezone_abbreviations_list() Function
PHP timezone_identifiers_list() Function
PHP timezone_location_get() Function
PHP timezone_name_from_abbr() Function
PHP timezone_name_get() Function
PHP timezone_offset_get() Function
PHP timezone_open() Function
PHP timezone_version_get() Function