PHP strtotime() Function12 Jan 2025 | 1 min read The PHP strtotime() function is used to convert an English text datetime into a Unix timestamp. SyntaxParameters
ReturnThis function returns a timestamp on success, FALSE otherwise. Example 1Output: 1533572997 1128297600 1533590997 1534177797 1534462202 1534118400 1533427200 Example 2Output: 1534032000 2018-08-12 Example 3Output: 1533859200 2018-08-10 Next TopicPhp-time-function |
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
The PHP time() function is used to return the current time as a UNIX timestamp. This function would work by our server time and can be formatted easily. Syntax int time ( void ) Example 1 <?php $today=time(); echo($today . "\n"); echo(date("Y-m-d",$today)); ?> Output: 1533574329 2018-08-06 Example 2 <?php $time1 = time(); echo($time1); echo "\n"; echo(date("F d, Y h:i:s A", $time1)); ...
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
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
This function returns the default timezone. It is used by all the date and time functions of the PHP. Note : timezone will be returned as a string. Syntax string date_default_timezone_get ( void ) Return This function returns a string. Example 1 <?php echo date_default_timezone_get(); ?> Output: UTC Example 2 <?php ...
1 min read
This date_timezone_set() function is used to set the time zone for the DateTime object. Syntax void date_timezone_set ( DateTime $object, DateTimeZone $timezone ) Parameters Parameter Description Required/Optional object Specifies a DateTime object required timezone Specifies a DateTimeZone object required Return Values This function returns NULL on success or FALSE on failure. Example 1 <?php $date=date_create("2018-07-25",timezone_open("Indian/Kerguelen")); echo date_format($date,"Y-m-d H:i:sP") . "\n"; date_timezone_set($date,timezone_open("Indian/Maldives")); echo date_format($date,"Y-m-d H:i:sP"); ?> Output: 2018-07-25 00:00:00+05:00 2018-07-25...
1 min read
This idate() function is used to examine all the different formats of local date and time. Syntax int idate ( string $format [, int $timestamp = time() ] ) Parameters Parameter Description Required/Optional Format Specifies how to return the result required timestamp Specifies a Unix timestamp that represents the date and/or time to be formatted. optional Return This function...
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 date_sun_info() function is used to return all the information about twilight begin/end and sunset/sunrise time for a specific time and location. Syntax array date_sun_info ( int $time , float $latitude , float $longitude ) Note :here value of latitude is 31.7667 and longitude is 35.2333. Parameters Parameter Description Required/Optional timestamp Specifies a timestamp Required latitude Specifies...
1 min read
The gmdate() function is used to changethe GMT/UTC date and time and output is returned in form of data string. It also modifies the date and time format in readable form. Syntax string gmdate ( string $format [, int $timestamp = time() ] ) Parameters Parameter Description Required/Optional Format Specifies the format of...
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