1. Home
  2. Computer Science MCQs
  3. PHP
  4. To create an object and set the date to JUNE 22, 2013…

Added 19 Jan 2024

To create an object and set the date to JUNE 22, 2013, which one of the following statement should be executed?

  1. $date = Date(“22 JUNE 2013″)
  2. $date = new Date(“JUNE 22 2013″)
  3. $date = DateTime(“22 JUNE 2013″)
  4. $date = new DateTime(“22 JUNE 2013″) Correct answer

Correct answer

D. $date = new DateTime(“22 JUNE 2013″)

17 views

MCQSEXAM

Explanation

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.

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More PHP MCQs

Practise all PHP MCQs

Similar MCQs