Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strtotime() DateTime class analog method

Tags:

Is there a method of DateTime class which acts like strtotime() core PHP function?

For example strtotime('last monday');

like image 840
s.webbandit Avatar asked Dec 05 '12 12:12

s.webbandit


People also ask

How do you get a date from Strtotime?

Code for converting a string to dateTime$date = strtotime ( $input ); echo date ( 'd/M/Y h:i:s' , $date );

Which is a valid Strtotime () function in PHP?

The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.

What does Strtotime return?

Return Values PHP strtotime() function returns a timestamp value for the given date string. Incase of failure, this function returns the boolean value false.

How do you add hours on Strtotime?

$timestamp = strftime("%Y-%m-%d %h:%M:%S %a", time ()); I simply want to add three hours and echo it out. I have seen the way where you can do the 60 * 60 * 3 method or the hard code "+ 3 hours" where it understands the words.


1 Answers

That would be DateTime::__construct:

$date = new DateTime('Sunday'); 
like image 76
deceze Avatar answered Sep 30 '22 20:09

deceze