Date And Timestamp(Php ) Questions and Answers

Question 1. Which one of the following function is useful for producing a timestamp based on a given date and time.
  1.    time()
  2.    mktime()
  3.    mrtime()
  4.    mtime()
Explanation:-
Answer: Option B. -> mktime()

Question 2. Which function displays the web page’s most recent modification date?
  1.    lastmod()
  2.    getlastmod()
  3.    last_mod()
  4.    get_last_mod()
Explanation:-
Answer: Option B. -> getlastmod()
The getlastmod() function returns the value of the page’s Last Modified header or FALSE in the case of an error.

Question 3. Say you want to calculate the date 45 days from the present date which one of the following statement will you use?
  1.    totime(“+45”)
  2.    totime(“+45 days”)
  3.    strtotime(“+45 days”)
  4.    strtotime(“-45 days”)
Explanation:-
Answer: Option C. -> strtotime(“+45 days”)
The strtotime() function and GNU date syntax is used to calculating the date x days from the present date.

Question 4. What will be the output of the following PHP code? If say date is 22/06/2013.
  1.    30
  2.    22
  3.    JUNE
  4.    2013
Explanation:-
Answer: Option A. -> 30
The t parameter is used to determine the number of days in the current month.

Question 5. 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”)
Explanation:-
Answer: Option D. -> $date = new DateTime(“22 JUNE 2013”)
The dateTime() method is class constructor. You can set the date either at the time of instantiation or later by using a variety of mutators.

Question 6. Which of the following statements can be used to set the time zone in individual scripts?
  1.    date_set_timezone(‘Europe/London’);
  2.    date_default_timezone_set(‘Europe/London’);
  3.    date_set_default_timezone(‘Europe/London’);
  4.    date_default_timezone(‘Europe/London’);
Explanation:-
Answer: Option B. -> date_default_timezone_set(‘Europe/London’);
You can also use ini_set(‘date.timezone’, ‘Europe/London’);.

Question 7. Which method enables you to calculate whether daylight saving time is in force at a specific date and time?
  1.    getOffset()
  2.    getTranitions()
  3.    ISODate()
  4.    savingTime()
Explanation:-
Answer: Option B. -> getTranitions()
This outputs a multidimensional array listing past and future changes to the offset from UTC for a DateTimeZone object.

Question 8. Among the four PHP DateTimeZone classes given below how many are static?
1. listAbbreviations()
2. getName()
3. getOffset()
4. listIdentifiers()
  1.    1
  2.    2
  3.    3
  4.    4
Explanation:-
Answer: Option B. -> 2
listAbbreviations() and listIdentifiers() are static methods.

Question 9. Among the four PHP DateTimeZone classes given below how many are nonstatic?
1. _construct()
2. getName()
3. getOffset()
4. getTransitions()
  1.    1
  2.    2
  3.    3
  4.    4
Explanation:-
Answer: Option D. -> 4
All of the given methods are non static.

Question 10. Which of the following statements can be used to add two months to the existing date?
  1.    $date->modify(‘+2 months’);
  2.    $date = modify(‘+2 months’);
  3.    $date = modify(‘2+ months’);
  4.    $date->modify(‘2+ months’);
Explanation:-
Answer: Option A. -> $date->modify(‘+2 months’);
To change the date stored by a DateTime object after it has been created, you use DateTime::modify() with a natural language expression.