This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Date and Timestamp”.
1. What will be the output of the following PHP code?
<?php
echo (checkdate(4,31,2010) ? 'Valid' : 'Invalid');
?>
a) TRUE
b) FALSE
c) Valid
d) Invalid
View Answer
Explanation: The function checkdate() is used to validate a Gregorian date. In the program, April has 30 days and the above date is 31 therefore Invalid is returned.
2. The date() function returns ___ representation of the current date and/or time.
a) Integer
b) String
c) Boolean
d) Float
View Answer
Explanation: The function date() is used to format a local date and time, and it will return the formatted date string. The syntax of this function is string date(string format [, int timestamp]).
3. Which one of the following format parameter can be used to identify timezone?
a) T
b) N
c) E
d) I
View Answer
Explanation: When the format is E the time zone is identified and returned, for example, America/New York. N denotes ISO-8601 numeric representation of the day of the week, T denotes time zone abbreviation, I denotes whether or not the date is in daylight saving time.
4. If the format is F then which one of the following will be returned?
a) Complete text representation of month
b) Day of month, with leading zero
c) Daylight saving time
d) Day of month, without zeros
View Answer
Explanation: F represents a full textual representation of a month, such as January or March. Day of month, with leading zero is represented by D, Daylight saving time by I, Day of month without zeros by j.
5. What will be the output of the following code? (If say date is 22/06/2013.)
<?php
echo "Today is ".date("F d, Y");
?>
a) Today is 22 June, 2013
b) Today is 22-06-2013
c) Today is 06-22-2013
d) Today is June 22, 2013
View Answer
Explanation: The function date() is used to format a local date and time, and it will return the formatted date string. F is the parameter for complete text representation of month, d for day of month, and Y for 4 digit representation of year.
6. Which one of the following function is useful for producing a timestamp based on a given date and time?
a) time()
b) mktime()
c) mrtime()
d) mtime()
View Answer
Explanation: The function mktime() returns the Unix timestamp for a date. This function is same as gmmktime() except that the passed parameters represents a date not a GMT date.
7. Which function displays the web page’s most recent modification date?
a) lastmod()
b) getlastmod()
c) last_mod()
d) get_last_mod()
View Answer
Explanation: The function getlastmod() gets the time of the last modification of the main script of execution. It returns the value of the page’s last modified header or FALSE in the case of an error.
8. What will be the output of the following PHP code? (If say date is 22/06/2013.)
<?php
printf( date("t") );
?>
a) 30
b) 22
c) JUNE
d) 2013
View Answer
Explanation: The t parameter is used to determine the number of days in the current month.
9. Suppose you want to calculate the date 45 days from the present date which one of the following statement will you use?
a) totime(“+45”)
b) totime(“+45 days”)
c) strtotime(“+45 days”)
d) strtotime(“-45 days”)
View Answer
Explanation: The strtotime() function and GNU date syntax is used to calculating the date x days from the present date.
10. To create an object and set the date to JUNE 22, 2013, which one of the following statement should be executed?
a) $date = Date(“22 JUNE 2013”)
b) $date = new Date(“JUNE 22 2013”)
c) $date = DateTime(“22 JUNE 2013”)
d) $date = new DateTime(“22 JUNE 2013”)
View Answer
Explanation: 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.
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all questions on PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.
- Practice Programming MCQs
- Check Information Technology Books
- Practice MCA MCQs
- Check PHP Books
- Apply for Programming Internship