
- PHP - Home
- PHP - Roadmap
- PHP - Introduction
- PHP - Installation
- PHP - History
- PHP - Features
- PHP - Syntax
- PHP - Hello World
- PHP - Comments
- PHP - Variables
- PHP - Echo/Print
- PHP - var_dump
- PHP - $ and $$ Variables
- PHP - Constants
- PHP - Magic Constants
- PHP - Data Types
- PHP - Type Casting
- PHP - Type Juggling
- PHP - Strings
- PHP - Boolean
- PHP - Integers
- PHP - Files & I/O
- PHP - Maths Functions
- PHP - Heredoc & Nowdoc
- PHP - Compound Types
- PHP - File Include
- PHP - Date & Time
- PHP - Scalar Type Declarations
- PHP - Return Type Declarations
- PHP - Operators
- PHP - Arithmetic Operators
- PHP - Comparison Operators
- PHP - Logical Operators
- PHP - Assignment Operators
- PHP - String Operators
- PHP - Array Operators
- PHP - Conditional Operators
- PHP - Spread Operator
- PHP - Null Coalescing Operator
- PHP - Spaceship Operator
- PHP Control Statements
- PHP - Decision Making
- PHP - If…Else Statement
- PHP - Switch Statement
- PHP - Loop Types
- PHP - For Loop
- PHP - Foreach Loop
- PHP - While Loop
- PHP - Do…While Loop
- PHP - Break Statement
- PHP - Continue Statement
- PHP Arrays
- PHP - Arrays
- PHP - Indexed Array
- PHP - Associative Array
- PHP - Multidimensional Array
- PHP - Array Functions
- PHP - Constant Arrays
- PHP Functions
- PHP - Functions
- PHP - Function Parameters
- PHP - Call by value
- PHP - Call by Reference
- PHP - Default Arguments
- PHP - Named Arguments
- PHP - Variable Arguments
- PHP - Returning Values
- PHP - Passing Functions
- PHP - Recursive Functions
- PHP - Type Hints
- PHP - Variable Scope
- PHP - Strict Typing
- PHP - Anonymous Functions
- PHP - Arrow Functions
- PHP - Variable Functions
- PHP - Local Variables
- PHP - Global Variables
- PHP Superglobals
- PHP - Superglobals
- PHP - $GLOBALS
- PHP - $_SERVER
- PHP - $_REQUEST
- PHP - $_POST
- PHP - $_GET
- PHP - $_FILES
- PHP - $_ENV
- PHP - $_COOKIE
- PHP - $_SESSION
- PHP File Handling
- PHP - File Handling
- PHP - Open File
- PHP - Read File
- PHP - Write File
- PHP - File Existence
- PHP - Download File
- PHP - Copy File
- PHP - Append File
- PHP - Delete File
- PHP - Handle CSV File
- PHP - File Permissions
- PHP - Create Directory
- PHP - Listing Files
- Object Oriented PHP
- PHP - Object Oriented Programming
- PHP - Classes and Objects
- PHP - Constructor and Destructor
- PHP - Access Modifiers
- PHP - Inheritance
- PHP - Class Constants
- PHP - Abstract Classes
- PHP - Interfaces
- PHP - Traits
- PHP - Static Methods
- PHP - Static Properties
- PHP - Namespaces
- PHP - Object Iteration
- PHP - Encapsulation
- PHP - Final Keyword
- PHP - Overloading
- PHP - Cloning Objects
- PHP - Anonymous Classes
- PHP Web Development
- PHP - Web Concepts
- PHP - Form Handling
- PHP - Form Validation
- PHP - Form Email/URL
- PHP - Complete Form
- PHP - File Inclusion
- PHP - GET & POST
- PHP - File Uploading
- PHP - Cookies
- PHP - Sessions
- PHP - Session Options
- PHP - Sending Emails
- PHP - Sanitize Input
- PHP - Post-Redirect-Get (PRG)
- PHP - Flash Messages
- PHP AJAX
- PHP - AJAX Introduction
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP XML
- PHP - XML Introduction
- PHP - Simple XML Parser
- PHP - SAX Parser Example
- PHP - DOM Parser Example
- PHP Login Example
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP Advanced
- PHP - MySQL
- PHP.INI File Configuration
- PHP - Array Destructuring
- PHP - Coding Standard
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Try…Catch
- PHP - Bugs Debugging
- PHP - For C Developers
- PHP - For PERL Developers
- PHP - Frameworks
- PHP - Core PHP vs Frame Works
- PHP - Design Patterns
- PHP - Filters
- PHP - JSON
- PHP - Exceptions
- PHP - Special Types
- PHP - Hashing
- PHP - Encryption
- PHP - is_null() Function
- PHP - System Calls
- PHP - HTTP Authentication
- PHP - Swapping Variables
- PHP - Closure::call()
- PHP - Filtered unserialize()
- PHP - IntlChar
- PHP - CSPRNG
- PHP - Expectations
- PHP - Use Statement
- PHP - Integer Division
- PHP - Deprecated Features
- PHP - Removed Extensions & SAPIs
- PHP - PEAR
- PHP - CSRF
- PHP - FastCGI Process
- PHP - PDO Extension
- PHP - Built-In Functions
PHP date_sun_info() Function
Definition and Usage
The date_sun_info() function accepts time, latitudes and longitudes of a location and gives information about sunrise/sunset and, begin/end of the twilight, in the given location.
Syntax
date_sun_info($timestamp, $latitude, $longitude)
Parameters
Sr.No | Parameter & Description |
---|---|
1 |
timestamp (Mandatory) This specifies a timestamp. |
2 |
latitude (Mandatory) This specifies latitude of a location. |
3 |
longitude (Mandatory) This specifies longitude of a location. |
Return Values
PHP date_sun_info() function returns an array containing the information about sunrise/sunset and, begin/end of the twilight for the given day in the specified location.
PHP Version
This function was first introduced in PHP Version 5.2.0 and, works with all the later versions.
Example
Following example demonstrates the usage of the date_sun_info() function −
<?php $sun_info = date_sun_info("02-17-2012", 20.5937, 78.9629); print_r($sun_info); ?>
This will produce following result −
Array ( [sunrise] => 4818 [sunset] => 44087 [transit] => 24453 [civil_twilight_begin] => 3381 [civil_twilight_end] => 45524 [nautical_twilight_begin] => 1729 [nautical_twilight_end] => 47176 [astronomical_twilight_begin] => 98 [astronomical_twilight_end] => 48807 )
Example
Following example gets the info on a the same date at different location −
<?php $sun_info = date_sun_info("02-17-2012", 37.0902, 95.7129); print_r($sun_info); ?>
This will produce following result −
Array ( [sunrise] => 3038 [sunset] => 37825 [transit] => 20431 [civil_twilight_begin] => 1307 [civil_twilight_end] => 39556 [nautical_twilight_begin] => -642 [nautical_twilight_end] => 41505 [astronomical_twilight_begin] => -2538 [astronomical_twilight_end] => 43402 )
Example
Following example gets the info at location in different dates −
<?php $time = "2000-01-01"; $latitude = 31.7667; $longitude = 35.2333; print_r(date_sun_info($time, $latitude, $longitude)); $time = "2010-01-01"; print_r(date_sun_info($time, $latitude, $longitude)); $time = "2020-01-01"; print_r(date_sun_info($time, $latitude, $longitude)); ?>
This will produce following result −
Array ( [sunrise] => 16742 [sunset] => 53161 [transit] => 34951 [civil_twilight_begin] => 15138 [civil_twilight_end] => 54765 [nautical_twilight_begin] => 13316 [nautical_twilight_end] => 56587 [astronomical_twilight_begin] => 11534 [astronomical_twilight_end] => 58369 ) Array ( [sunrise] => 16742 [sunset] => 53161 [transit] => 34951 [civil_twilight_begin] => 15138 [civil_twilight_end] => 54765 [nautical_twilight_begin] => 13316 [nautical_twilight_end] => 56587 [astronomical_twilight_begin] => 11534 [astronomical_twilight_end] => 58369 ) Array ( [sunrise] => 16742 [sunset] => 53161 [transit] => 34951 [civil_twilight_begin] => 15138 [civil_twilight_end] => 54765 [nautical_twilight_begin] => 13316 [nautical_twilight_end] => 56587 [astronomical_twilight_begin] => 11534 [astronomical_twilight_end] => 58369 )
Example
<?php $sun_info = date_sun_info(strtotime("2017-07-12"), 20.5937, 78.9629); foreach ($sun_info as $key => $val) { echo "$key: " . date("H:i:s", $val) . "\n"; } ?>
This will produce following result −
sunrise: 00:11:03 sunset: 13:28:33 transit: 06:49:48 civil_twilight_begin: 23:46:45 civil_twilight_end: 13:52:51 nautical_twilight_begin: 23:17:48 nautical_twilight_end: 14:21:47 astronomical_twilight_begin: 22:47:55 astronomical_twilight_end: 14:51:41