To create an object and set the date to JUNE 22, 2013, which one of the following statement should be executed?
Correct answer
D. $date = new DateTime(“22 JUNE 2013″)
17 views
D. $date = new DateTime(“22 JUNE 2013″)
17 views
A DateTime object is created with the DateTime class constructor: new DateTime("22 JUNE 2013"). Date() is a function that returns a string and there is no Date class in PHP, so options 1 and 2 are invalid; option 3 omits the new keyword.
Not sure why the answer is D? Ask here and get an explanation.