PHP gmmktime() Function6 Jan 2025 | 1 min read The gmmktime() function is used to find the day of that particular date. It returns the returns the Unix timestamp for a GMT date. SyntaxParameters
ReturnThis function returns an integer Unix timestamp. Example 1Output: Aug 3, 2000 was on a Tuesday Example 2Output: Aug 3, 2018 was on a Wednesday Example 3Output: Aug 3, 2020 was on a Saturday Next TopicPhp-gmstrftime-function |
The date_timestamp_get() function is used to return the Unix timestamp for today's date and time. Syntax date_timestamp_get(object); 0r DateTime::getTimestamp() Parameters Parameter Description Required/Optional object Specifies a DateTime object required Example 1 <?php $date=date_create(); echo date_timestamp_get($date); ?> Output: 1533132945 Example 2 <?php $date = new DateTime(); echo $date->getTimestamp(); ?> Output: 1533133630 TopicPhp-date-timezone-get-function ...
1 min read
This date_sunset() function is used to get the timing of sunset of a particular day and location. This function returns the sunset time of different locations. Syntax mixed date_sunset ( int $timestamp [, int $format = SUNFUNCS_RET_STRING [, float $latitude = ini_get("date.default_latitude") [, float $longitude = ini_get("date.default_longitude")...
1 min read
It returns new date and time. Syntax DateTime date_create ( [$time [, timezone]] ); Note : time and timezone are the optional parameters. Return This function returns the DateTime object on success or FALSE on failure. Example 1 <?php $datefind=date_create("2018-7-25 5:0:00",timezone_open("America/Chicago")); echo date_format($datefind,"Y/m/d H:iP"); ?> Output: 2018/07/25 05:00-05:00 Example 2 <?php $date=date_create("2018-07-27"); ...
1 min read
This function is used to return date in a specified formati.e format of year ,month and day . Syntax string date_format ( DateTime $object, string $format ) Parameters Parameter Description Required/Optional object Specifies Datetime object required format Specifies the format for the date required Return This function returns formatted date on success or FALSE on failure. Example 1 <?php $date=date_create("2018-03-15"); echo date_format($date,"Y/m/d H:i:s"); ?> Output: 2018/03/15...
1 min read
PHP date_interval_format() for formatting the interval, this function is used in the script. We can also write it as DateInterval::format(). Syntax DateInterval::format(format); Note: Here format is the required string. Return This function returns the formatted interval. Example 1 <?php $date1=date_create("2018-01-01"); $date2=date_create("2018-02-10"); $diff=date_diff($date1,$date2); echo $diff->format("Total number of days: %a."); echo "\n"; echo $diff->format("Total number of days: %R%a."); echo "\n"; echo $diff->format("Month:...
1 min read
The PHP timezone_offset_get() function is used to show the offset of the timezone from the GMT. Syntax int timezone_offset_get ( $object, $datetime ); Parameters Parameter Description Required/Optional object Specifies a DateTimeZone object required datetime Specifies a date/time required Return This function returns time zone offset in seconds on success or FALSE on failure. Example 1 <?php $timezone=timezone_open("Asia/Taipei"); $dateTimeOslo=date_create("now",timezone_open("Europe/Oslo")); echo timezone_offset_get($timezone,$dateTimeOslo); ?> Output: 28800 Example 2 <?php $timezone=timezone_open("Africa/Juba "); $dateTimeAmsterdam=date_create("now",timezone_open("Europe/Amsterdam ")); echo...
1 min read
This PHP localtime() function is used to print the time in the form of indexed and associative array. It returns the local time. Syntax localtime(timestamp,is_assoc); Parameters Parameter Description Required/Optional timestamp Specifies a Unix timestamp optional Is_assoc Specifies whether to return an associative array or indexed array. optional Example 1 <?php print_r(localtime()); echo "<br><br>"; print_r(localtime(time(),true)); ?> Output: Array ( [0] => 45 ...
2 min read
The date_sub() function is used to subtracts or deduce some formatted data of the date i.e date, month,year, hours,minutes, seconds etc. Syntax date_sub(object,interval); Parameters Parameter Description Required/Optional Object Specifies a DateTime object required Interval Specifies a DateInterval object required Example 1 <?php $date=date_create("2018-07-15"); date_sub($date,date_interval_create_from_date_string("10 days")); echo date_format($date,"Y-m-d"); ?> Output: 2018-07-05 Example 2 <?php $date=date_create("2020-12-15"); date_sub($date,date_interval_create_from_date_string("5 days")); echo date_format($date,"Y-m-d"); ?> Output: 2020-12-10 Example 3 <?php $date = date_create('2018-07-15'); date_sub($date, date_interval_create_from_date_string('5 years')); echo date_format($date, 'Y-m-d') . "\n"; ?> Output: 2013-07-15 Example 4 <?php $date1...
1 min read
This function finds out the difference between the two DateTime objects. It represents the difference of days between two dates. Syntax date_diff($datetime1,$datetime2,$absolute); Parameters Parameter Description Required/Optional datetime1 Specifies a DateTime object Required datetime2 Specifies a DateTime object Required absolute Specifies a Boolean value optional Example 1 <?php $date1=date_create("2018-03-1"); $date2=date_create("2018-04-1"); $diff=date_diff($date1,$date2); echo $diff->format("%R%a days"); ?> Output: +31 days Example 2 <?php function dateDiff($start, $end) { $start_t = strtotime($start); $end_t = strtotime($end); $differ = $end_t - $start_t; return...
1 min read
This PHP timezone_open() function is used to return the name of the timezone and also create a new DateTimeZone object. Syntax timezone_open ( $timezone ) Parameters timezone: It specifies a timezone. Return This function returns the DateTimeZone object on success or FALSE on failure. Example 1 <?php $timezone=timezone_open("Europe/Paris"); echo timezone_name_get($timezone); ?> Output: Europe/Paris Example 2 <?php $timezone=timezone_open("Europe/Oslo"); echo timezone_name_get($timezone); ?> Output: Europe/Oslo TopicPhp-timezone-version-get-function ...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India