PHP date_create() function6 Jan 2025 | 1 min read It returns new date and time. SyntaxNote : time and timezone are the optional parameters.ReturnThis function returns the DateTime object on success or FALSE on failure. Example 1Output: 2018/07/25 05:00-05:00 Example 2Output: 2018/07/27 Example 3Output: 2018-12-20 Next TopicPhp-date-date-set-function |
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
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
This function is used when a certain amount of time is added or subtracted from the standard UTC to get the current civil time that had been already set on DST(daylight saving time). Syntax int date_offset_get ( DateTime $object ) Parameters Parameter Description Required/Optional Object Specifies a DateTime object Required Return This function returns DST offset...
1 min read
The PHP strtotime() function is used to convert an English text datetime into a Unix timestamp. Syntax int strtotime ( string $time [, int $now = time() ] ) Parameters Parameter Description Required/Optional Time Specifies a date/time string Required Now A timestamp that calculate relative dates. Optional Return This function returns a timestamp on success, FALSE otherwise. Example 1 <?php echo(strtotime("now") ....
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
The date_timestamp_set() function is used to set the date and time based on unix timestamp. It returns a datetime object and unix timestamp represents the date. Syntax date_timestamp_set(object,unixtimestamp); Parameters Parameter Description Required/Optional object Specifies a DateTime object required unixtimestamp Specifies a Unix timestamp representing the date optional Example 1 <?php $date1=date_create(); date_timestamp_set($date1,1533132945); echo date_format($date1,"U = Y-m-d H:i:s"); ?> Output: 1533132945 = 2018-08-01 14:15:45 Example 2 <?php $date=date_create(); date_timestamp_set($date,1533133630); echo date_format($date,"U...
1 min read
This function sets the default timezone. It is used by all the date and time functions of the PHP. Syntax bool date_default_timezone_set ( string $timezone_identifier ) Parameters timezone_identifier: The timezone identifier like UTC or Europe/Lisbon. The list of valid identifiers is available in the List of Supported Timezones. Return This function...
1 min read
The date_time_set() function is used to set the time in a specified format. It returns a datetime object at the end. Syntax date_time_set(object,hour,minute,second); Parameters Parameter Description Required/Optional object Specifies a DateTime object required hour Specifies the hour of the time Specifies the hour of the time minute Specifies the minute of the time required second Specifies the second of the time optional Example 1 <?php $date1=date_create("2018-7-31"); date_time_set($date1,10,24); echo...
1 min read
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
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
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