PHP date_add() function6 Jan 2025 | 1 min read This function is used to add the days, months, years to the date. SyntaxParameters
Example 1Output: 2018-03-20 Example 2Output: 2020-12-10 00:20:25 Next TopicPhp-date-create-function |
This date_timezone-get() function is used to return the time zone of the given DateTime object in the script. Syntax DateTimeZone date_timezone_get ( DateTime $object ) Parameters Parameter Description Required/Optional object Specifies a DateTime object required Return Values This function returns the DateTimeZone object on success or FALSE on failure. Example 1 <?php $date1=date_create(null,timezone_open("Indian/Maldives")); $ind=date_timezone_get($date1); echo timezone_name_get($ind); ?> Output: Indian/Maldives Example 2 <?php $date1=date_create(null,timezone_open("Pacific/Easter")); $paci=date_timezone_get($date1); echo timezone_name_get($paci); ?> Output: Pacific/Easter Example 3 <?php $date1=date_create(null,timezone_open("Europe/Istanbul")); $eu=date_timezone_get($date1); echo timezone_name_get($eu); ?> Output: Europe/Istanbul ...
1 min read
The gettimeofday() function is used to get the current time of the day. It returns a float value. Syntax mixed gettimeofday ([ bool $return_float = FALSE ] ) Parameters Parameter Description Required/Optional return_float Specifies a float value optional Return This function by default returns an array. If return_float is set, this function will return a float. Example...
1 min read
This function is used to provide the complete information of a particular date in a specified format and an associative array is returned by it. Syntax date_parse_from_format(format,date); Parameters Parameter Description Required/Optional Format Specifies the format required Date specifies a date required Return This function returns associative array with detailed info about given date. Example 1 <?php print_r(date_parse_from_format("mmddyyyy","05122018")); ?> Output: Array ( [year] => [month] =>...
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
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 function allows the modification in date and time. Syntax date_modify(object,modify); Parameters Parameter Description Required/Optional object Specifies a DateTime object return. Required modify Specifies a date/time string Required Return This function returns NULL on success or FALSE on failure. Example 1 <?php $date=date_create("2018-05-01"); date_modify($date,"+15 days"); echo date_format($date,"Y-m-d"); ?> Output: 2018-05-16 Example 2 <?php $date = new DateTime("2020-12-12"); $date->modify("+10 day"); echo $date->format("Y-m-d"); ?> Output: 2020-12-22 Example 3 <?php ...
1 min read
The PHP microtime() function is used to returns the current Unix timestamp with microseconds. Float value is return by this function. Syntax mixed microtime ([ bool $get_as_float = FALSE ] ) Parameters Parameter Description Required/Optional get_as_float specifies that the function should return a float optional Return This function returns a string in the form "msec sec",...
1 min read
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
If any error comes while parsing the date string, this function will show warnings/ errors in output. Syntax date_get_last_errors(); Example 1 <?php date_create('g$%^jngvnk'); print_r(date_get_last_errors()); ?> Output: Array ( [warning_count] => 1 [warnings] => Array ( ...
1 min read
The PHP timezone_identifiers_list() function is used to show an indexed array that contains all the identifiers of timezone. Syntax array timezone_identifiers_list(what,country); Parameters Parameter Description Required/Optional what Specifies a DateTimeZone optional country Specifies a country code optional Return Values This function returns array on success or FALSE on failure. Example 1 <?php // Print all timezones in Africa print_r(timezone_identifiers_list(1)); ?> Output: Array ( [0] =>...
3 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