Practice high-yield Programming & Software Development MCQs on Date And Timestamp with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
30
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
36 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
30
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/30 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 30 questions answered.
Question 1 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? <?php echo (checkdate( 4,31,2010 ) ? 'Valid' : 'Invalid' ) ; ?>
Correct Answer: Option D — Invalid
Detailed Academic Explanation:
April has 30 days and the above date is 31 therefore Invalid is returned.
💡Key Conceptual Anchor:Date And Timestamp
Question 2 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The date() function returns ___ representation of the current date and/or time.
Correct Answer: Option B — String
Detailed Academic Explanation:
The prototype of this function is: string date(string format [, int timestamp]).
💡Key Conceptual Anchor:Date And Timestamp
Question 3 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following format parameter can be used to identify timezone?
Correct Answer: Option C — E
Detailed Academic Explanation:
When the format is E the timezone is identified and returned…example America/New_York.
💡Key Conceptual Anchor:Date And Timestamp
Question 4 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If the format is F then which one of the following will be returned?
Correct Answer: Option A — Complete text representation of month
Detailed Academic Explanation:
Day of month, with leading zero is represented by D; Daylight saving time by I; Day of month, without zeros by j.
💡Key Conceptual Anchor:Date And Timestamp
Question 5 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following code? If say date is 22/06/2013. <?php echo "Today is " .date( "F d, Y" ) ?>
Correct Answer: Option D — Today is June 22, 2013
Detailed Academic Explanation:
F is the parameter for complete text representation of month, d for day of month, and Y for 4 digit representation of year.
💡Key Conceptual Anchor:Date And Timestamp
Question 6 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which function displays the web page’s most recent modification date?
Correct Answer: Option B — getlastmod()
Detailed Academic Explanation:
The getlastmod() function returns the value of the page’s Last Modified header or FALSE in the case of an error.
💡Key Conceptual Anchor:Date And Timestamp
Question 7 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code? If say date is 22/06/2013. <?php printf( date( "t" ) ) ?>
Correct Answer: Option A — 30
Detailed Academic Explanation:
The t parameter is used to determine the number of days in the current month.
💡Key Conceptual Anchor:Date And Timestamp
Question 8 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Say you want to calculate the date 45 days from the present date which one of the following statement will you use?
Correct Answer: Option C — strtotime(“+45 days”)
Detailed Academic Explanation:
The strtotime() function and GNU date syntax is used to calculating the date x days from the present date.
💡Key Conceptual Anchor:Date And Timestamp
Question 9 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
To create an object and set the date to JUNE 22, 2013, which one of the following statement should be executed?
Correct Answer: Option D — $date = new DateTime(“22 JUNE 2013”)
Detailed Academic 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.
💡Key Conceptual Anchor:Date And Timestamp
Question 10 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many methods does the DateTime class have?
Correct Answer: Option B — 9
Detailed Academic Explanation:
The DateTime class has nine methods, all of which are public.
💡Key Conceptual Anchor:Date And Timestamp
Question 11 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many constants does the DateTime class have?
Correct Answer: Option D — 11
Detailed Academic Explanation:
The DateTime class has 11 constants, no static properties or methods.
💡Key Conceptual Anchor:Date And Timestamp
Question 12 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method is simply an object-oriented version of date()?
Correct Answer: Option A — DateTime::format()
Detailed Academic Explanation:
The format() method is simply an object-oriented version of date(). It takes $dateFormat as an argument. $dateFormat is a string consisting of the same date formatting characters accepted by the procedural date() function.
💡Key Conceptual Anchor:Date And Timestamp
Question 13 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is the right way to use the DateTime class?
Correct Answer: Option C — $date = new DateTime()
Detailed Academic Explanation:
The way you use the DateTime class is like any other class: instantiate an object, and store it in a variable.
💡Key Conceptual Anchor:Date And Timestamp
Question 14 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following PHP code if date is 24/02/2008? <?php $date = new DateTime () ; echo $date- > format( 'l,F,js,Y' ) ?>
Correct Answer: Option A — Sunday, February 24th 2008
Detailed Academic Explanation:
The format() method displays the date in same way as standard date function().
💡Key Conceptual Anchor:Date And Timestamp
Question 15 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following statements can be used to set the time zone in individual scripts?
Correct Answer: Option B — date_default_timezone_set(‘Europe/London’)
Detailed Academic Explanation:
You can also use ini_set(‘date.timezone’, ‘Europe/London’);.
💡Key Conceptual Anchor:Date And Timestamp
Question 16 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Among the four PHP DateTimeZone classes given below how many are static? 1. listAbbreviations() 2. getName() 3. getOffset() 4. listIdentifiers()
Correct Answer: Option B — 2
Detailed Academic Explanation:
listAbbreviations() and listIdentifiers() are static methods.
💡Key Conceptual Anchor:Date And Timestamp
Question 17 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Among the four PHP DateTimeZone classes given below how many are nonstatic? 1. _construct() 2. getName() 3. getOffset() 4. getTransitions()
Correct Answer: Option D — 4
Detailed Academic Explanation:
All of the given methods are non static.
💡Key Conceptual Anchor:Date And Timestamp
Question 18 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following statements can be used to add two months to the existing date?
Correct Answer: Option A — $date->modify(‘+2 months’)
Detailed Academic Explanation:
To change the date stored by a DateTime object after it has been created, you use DateTime::modify() with a natural language expression.
💡Key Conceptual Anchor:Date And Timestamp
Question 19 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which method enables you to calculate whether daylight saving time is in force at a specific date and time?
Correct Answer: Option B — getTranitions()
Detailed Academic Explanation:
This outputs a multidimensional array listing past and future changes to the offset from UTC for a DateTimeZone object.
💡Key Conceptual Anchor:Date And Timestamp
Question 20 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which one of the following function is useful for producing a timestamp based on a given date and time.
Correct Answer: Option B — mktime()
Detailed Academic Explanation:
mktime() is the correct answer to “Which one of the following function is useful for producing a timestamp based on a given date and time.”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
Question 21 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following functions do not return a timestamp? 1. time() 2. date() 3. strtotime() 4. localtime() 5. gmmktime()
Correct Answer: Option D — Option 2 and 4
Detailed Academic Explanation:
Option 2 and 4 is the correct answer to “Which of the following functions do not return a timestamp? 1. time() 2. date() 3. strtotime() 4. localtime() 5. gmmktime()”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
Question 22 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The getdate() function returns
Correct Answer: Option C — An array
Detailed Academic Explanation:
An array is the correct answer to “The getdate() function returns”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
Question 23 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
.......... Returns the time of sunrise for a given day / location.
Correct Answer: Option B — date_sunrise()
Detailed Academic Explanation:
date_sunrise() is the correct answer to “.......... Returns the time of sunrise for a given day / location.”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
Question 24 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will the following script output? <?php $time = strtotime ( '2004/01/01' ) ; echo date ( 'H:i:s', $time ) ; ?>
Correct Answer: Option C — 00:i:00
Detailed Academic Explanation:
00:i:00 is the correct answer to “What will the following script output? <?php $time = strtotime ( '2004/01/01' ) ; echo date ( 'H:i:s', $time ) ; ?>”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
Question 25 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
................Checks a date for numeric validity.
Correct Answer: Option D — checkdate
Detailed Academic Explanation:
checkdate is the correct answer to “................Checks a date for numeric validity.”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
Question 26 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the difference, in seconds, between the current timestamp in the GMT time zone and the current timestamp in your local time zone?
Correct Answer: Option B — There is no difference
Detailed Academic Explanation:
There is no difference is the correct answer to “What is the difference, in seconds, between the current timestamp in the GMT time zone and the current timestamp in your local time zone”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
Question 27 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
You must make a call to ................... to specify what time zone you want calculations to take place in before calling any date functions.
Correct Answer: Option A — date_default_timezone_set()
Detailed Academic Explanation:
date_default_timezone_set() is the correct answer to “You must make a call to ................... to specify what time zone you want calculations to take place in before calling any date functions.”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
Question 28 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What would happen if the following script were run on a Windows server set to Moscow, Russia’s time zone? <?php echo gmmktime ( 0, 0, 0, 1, 1, 1970 ) ; ?>
Correct Answer: Option B — It would output the number -1
Detailed Academic Explanation:
It would output the number -1 is the correct answer to “What would happen if the following script were run on a Windows server set to Moscow, Russia’s time zone? <?php echo gmmktime ( 0, 0, 0, 1, 1, 1970 ) ; ?>”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
Question 29 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The ......... function parses an English textual date or time into a Unix timestamp.
Correct Answer: Option C — strtotime()
Detailed Academic Explanation:
strtotime() is the correct answer to “The ......... function parses an English textual date or time into a Unix timestamp.”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
Question 30 of 30
★ FPSC
★ PPSC
★ FPSC
★ PPSC
................ Formats a local time or date according to locale settings.
Correct Answer: Option A — strftime
Detailed Academic Explanation:
strftime is the correct answer to “................ Formats a local time or date according to locale settings.”. This question is standard in competitive examination syllabi for Date And Timestamp.
💡Key Conceptual Anchor:Date And Timestamp
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.