PHP Programming Basics Practice Test: Working with Dates in PHP — Flashcards | PHP & Programming | FatSkills

PHP Programming Basics Practice Test: Working with Dates in PHP — Flashcards

Fast review mode: answers are shown by default so you can skim quickly. Hide them if you want to self-test.

Quiz on Date and Timestamp & Working with Dates in PHP.

PHP has a variety of functions for working with dates and timestamps, including the date() function, which formats a timestamp into a more readable date and time, and the DateTime class, which provides an object-oriented approach to working with dates and times. 

The syntax for the date() function is: date(format,timestamp) [1] 
The format parameter specifies how to format the date or time, and the timestamp parameter specifies a timestamp. If omitted, the current date and time will be used. 

Here are some characters that are commonly used for dates:
d:
Represents the day of the month (01 to 31)
m: Represents a month (01 to 12)
Y: Represents a year (in four digits)
l (lowercase 'L'): Represents the day of the week 

Here are some other PHP functions that can be used to work with dates and timestamps:
time():
Returns the current Unix timestamp, which represents the number of seconds since January 1, 1970
strtotime(): Converts a date string into a Unix timestamp
DateTime::format(): Formats a DateTime object as a string using specific formatting codes
DateTime::timezone(): Sets the timezone for a DateTime object

1 of 20 Ready
What will be the output of the following PHP code?
<?php
echo (checkdate(4,31,2010) ? 'Valid' : 'Invalid');
?>
Invalid
Shortcuts
Prev Space Show / hide Next
Turn this into a study set.
Sign in with Google to save tricky questions to your reminder list and resume on any device.
Sign in with Google Free • no extra password