date and time functions Flashcards
1
Q
What does the time() function do?
A
It returns a unix timestamp, counting the number of seconds from the epoch (Jan 1, 1970)
2
Q
How do you obtain the timestamp for one week from now?
A
Add 7 days times 24 hours times 60 minutes times 60 seconds to the current timestamp.
echo time() + 7 * 24 * 60 * 60;
3
Q
How do you create a timestamp for a given date?
A
You can use the mktime function. Its output is the timestamp 946684800 for the first second of the first minute of the first hour of the first day of the year 2000: echo mktime (0, 0, 0, 1, 1, 2000); The parameters to pass from left to right: hour (0-23), minute(0-59), seconds(0-59), month(1-12), day(1-31), year (1970-2038 or 1901-2038)
4
Q
What are the parameters for the date function?
A
date($format, $timestamp);
5
Q
How can you check whether a user has submitted a valid date?
A
Using checkdate()
if (checkmate($month, $day, $year)) echo “Date is valid”;
else echo “Date is invalid”;