PHP | strtotime() Function Last Updated : 31 Jul, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The strtotime() function is a built-in function in PHP which is used to convert an English textual date-time description to a UNIX timestamp. The function accepts a string parameter in English which represents the description of date-time. For e.g., "now" refers to the current date in English date-time description. The function returns the time in seconds since the Unix Epoch. We can return the English textual date-time in date format using the date() function. Syntax: strtotime ($EnglishDateTime, $time_now) Parameters: The function accepts two parameters as shown above and described below: $EnglishDateTime - This parameter specifies the English textual date-time description, which represents the date or time to be returned. The function parses the string and returns us the time in seconds. The parameter is mandatory $time_now This parameter specifies the timestamp used to calculate the returned value. It is an optional parameter. Note: Since the time/date is not static, therefore the output will vary. Below programs illustrate the strtotime() function. Program 1: The below program demonstrates the strtotime() function when the english text is "now". php <?php // PHP program to demonstrate the strtotime() // function when the english text is "now" // prints current time in second // since now means current echo strtotime("now"), "\n"; // prints the current time in date format echo date("Y-m-d", strtotime("now"))."\n"; ?> Output: 1525378260 2018-05-03 Program 2: The below program demonstrates the strtotime() function when the english text is a date. php <?php // PHP program to demonstrate the strtotime() // function when the english text is a date // prints the converted english text in second echo strtotime("12th february 2017"), "\n"; // prints the above time in date format echo date("Y-m-d", strtotime("12th february 2017"))."\n"; ?> Output: 1486857600 2017-02-12 Program 3: The below program demonstrates the strtotime() function when the english text corresponds to any day. php <?php // PHP program to demonstrate the strtotime() // function when the english text corresponds to any // day // prints the converted english text in second echo strtotime("next sunday"), "\n"; // prints the above time in date format echo date("Y-m-d", strtotime("next sunday"))."\n"; ?> Output: 1525564800 2018-05-06 PHP is a server-side scripting language designed specifically for web development. You can learn PHP from the ground up by following this PHP Tutorial and PHP Examples. Comment More infoAdvertise with us Next Article PHP | time() Function G gopaldave Follow Improve Article Tags : Web Technologies PHP PHP-date-time Similar Reads PHP | strptime() Function The strptime() function is an inbuilt function in PHP which is used to parse a time / date generated with strftime() function. The date and format are sent as a parameter to the strptime() function and it returns an array on success or False on failure. The array returned by the strptime() function 2 min read PHP | strftime() Function The strftime() function is an inbuilt function in PHP that formats local time or date according to locale settings i.e. it formats local time or date for location set for it of a place. Syntax: strftime( $format, $timestamp ) Parameters: This function accept two parameters as mentioned above and des 5 min read PHP | time() Function The time() function is a built-in function in PHP which returns the current time measured in the number of seconds since the Unix Epoch. The number of seconds can be converted to the current date using date() function in PHP. Syntax: int time() Parameter: This function does not accepts any parameter 2 min read PHP | date_time_set() Function The date_time_set() function is an inbuilt function in PHP which is used to sets the time. This function resets the current time of the DateTime object to a different time. Syntax: Procedural style: date_time_set( $object, $hour, $minute, $second, $microseconds ) Object oriented style: DateTime::set 2 min read PHP | hrtime() Function The hrtime() function is an inbuilt function in PHP which returns the high-resolution time of the system. Syntax: mixed hrtime( bool $is_num_return ); Parameter: This function accepts a single parameter as mentioned above and described below: $is_num_return: It is optional parameter of Boolean type. 1 min read PHP | date_timezone_set() Function The date_timezone_set() function is an inbuilt function in PHP which is used to sets the time zone for the DateTime object. This function returns the DateTime object or False on failure. Syntax: Procedural style: date_timezone_set( $object, $timezone ) Object oriented style: DateTime::setTimezone( $ 2 min read Like