PHP date_parse() function6 Jan 2025 | 1 min read This date function work same as date_parse_from_format() that provides the complete information about the particular date in an specified format and return data in form of array. SyntaxParameters
ReturnThis function returns array with information about the parsed date on success or FALSE on failure. Example 1Output: Array ( [year] => 2018 [month] => 7 [day] => 10 [hour] => 12 [minute] => 30 [second] => 45 [fraction] => 0.5 [warning_count] => 0 [warnings] => Array Example 2Output: Array ( [year] => 2020 [month] => 7 [day] => 10 [hour] => 1 [minute] => 30 [second] => 60 [fraction] => 0 [warning_count] => 1 [warnings] => Array ( [22] => The parsed time was invalid ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => ) Example 3Output: Array ( [year] => 2018 [month] => 7 [day] => 12 [hour] => 12 [minute] => 0 [second] => 0 [fraction] => 0.5 [warning_count] => 0 [warnings] => Array ( ) Next TopicPhp-date-sub-function |
shows day, month and year altogether. Date and time are stored in computer in UNIX Timestamp format. It calculates time in number of seconds on GMT (greenwich mean time) i.e started from January 1, 1970, 00:00:00 GMT. Syntax string date ( string $format [, int $timestamp...
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_location_get() function is used to show the information of the location of the given timezone. Syntax timezone_location_get(object); Parameters Object: It specifies a DateTimeZone object. Return Returns array on success or FALSE on failure. Example 1 <?php $timezone=timezone_open("Asia/Taipei"); print_r(timezone_location_get($timezone)); ?> Output: Array ( [country_code] => TW [latitude] => 25.05 ...
1 min read
This function is used to add the days, months, years to the date. Syntax date_add(object,interval); Parameters Parameter Description object Required. Specifies a DateTime object interval Required. Specifies a DateInterval object Example 1 <?php $datefind=date_create("2018-03-16"); date_add($datefind,date_interval_create_from_date_string("4 days")); echo date_format($datefind,"Y-m-d"); ?> Output: 2018-03-20 Example 2 <?php $date=date_create("2018-12-10"); date_add($date, date_interval_create_from_date_string("2 year ...
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. Syntax int gmmktime(hour,minute,second,month,day,year,is_dst); Parameters Parameter Description Required/Optional Hour Specifies the hour optional Minute Specifies the minute optional Second Specifies the second optional Month Specifies the month optional Day Specifies the day optional Year Specifies the year optional Is_dst specifies a GMT date optional Return This function returns an integer Unix...
1 min read
It is used to set a new date and formatting of date is also allowed. It returns a datetime object. Syntax void date_date_set ( DateTime $object, int $year, int $month, int $day ); Parameters Parameter Description object Required. Specifies a DateTime object returned year Required. Specifies the year of the date month Required. Specifies the month...
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
This date_sunrise() function is used to get the timing of sunrise of a particular day and location. This function returns the sunrise time of different locations. Syntax mixed date_sunrise ( int $timestamp [, int $format [, float $latitude [, float $longitude [, float $zenith...
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
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