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.
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”.
Program 2: The below program demonstrates the strtotime()
function when the english text is a date.
Program 3: The below program demonstrates the strtotime()
function when the english text corresponds to any day.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.