Site icon sharedsapience.info

PHP Date/Time Function Quiz 2: DateTime::setISODate(); DateTime::modify(); DateTime::getOffset(); date_parse_from_format(); date_parse(); DateTime::sub(); date_sun_info(); date_sunrise(); date_sunset(); DateTime::setTime(); and DateTime::getTimestamp().

First four rows of the PHP Date/Time Function Mini-Quiz 2, sized for mobile viewing.

An image of the first four rows of the PHP Date/Time Function Mini-Quiz 2, sized for mobile viewing.

HOW THE QUIZ WORKS:

Clicking the ‘randomize’ button situated above the reference table generates a new table whereby the function descriptions, function syntaxes, and function return values are randomized. The quiz involves matching the function descriptions, function syntaxes, and function return values to the correct function name. Information relating to the randomization of table cells will be displayed for three seconds, before disappearing.

On a desktop computer, table elements are selected by left-clicking the desired table cell and holding the left click in the mouse down position for one second before releasing the left click. The text inside the table cell will turn red to indicate that the one-second mouse left-click has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second left mouse-click process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second left mouse-click process on the original table cell.

To select a table element on a touchscreen device (mobile, tablet), simply touch the desired table cell and maintain the touch for one second before removing your finger from the screen. The text inside the table cell will turn red to indicate that the one-second touch has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second touch process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second touch process on the original table cell.

Normal touchscreen scrolling behaviour is exhibited by the cells with a light green background; cells without a light green background will not respond to normal touchscreen scrolling. The table is positioned in such a way that the user can also initiate touchscreen scrolling by swiping to the right or left of the table.

When a row consists of the correct function name, function description, function syntax, and function return value, the background colour of the row will change from ‘transparent’ to ‘khaki’; this provides visual feedback that the row is complete.

Once the entire table is complete, a paragraph of feedback will congratulate the user and provide the following information: date and time of quiz commencement; date and time of quiz completion; and the length of time it took the user to complete the quiz.

VIEWPORT OPTIONS:

An example of the layout designed for mobile phones
An example of the layout designed for tablets
An example of the layout designed for desktop computers

PURPOSE:

This webpage serves two purposes:

  1. It provides a reference table for the PHP date/time functions, with information extracted and condensed from w3schools.com and php.net.
  2. It enables users to complete a quiz related to the PHP date/time functions.

USAGE:

For each date/time function there are four table cells of information: the function name; the function description; the function syntax; and the function return value. There are three layouts available – ‘mobile‘, ‘tablet‘, and ‘desktop‘.

Click the relevant button below to display the PHP date/time functions reference table, sized appropriately for the desired viewport. A ‘RANDOMIZE‘ button appears above the reference table once the viewport is selected; clicking this button facilitates the commencement of a quiz.



Click the ‘RANDOMIZE‘ button to randomize the functional descriptions, the functional syntaxes, and the functional return information.



FUNCTION NAME FUNCTION DESCRIPTION FUNCTION SYNTAX FUNCTION RETURN VALUE
DateTime::setISODate()
date_isodate_set()

[Sets the ISO date]

Set a date according to the ISO 8601 standard, using weeks and day offsets rather than specific dates. Object-oriented style:
DateTime::setISODate(year, week, day [optional parameter]);
Procedural style:
date_isodate_set(datetime_object, year, week, day [optional parameter]);

[day specifies the offset from the first day of the week; default value is 1]

DateTime::setISODate(): returns the DateTime object for method chaining on success; FALSE on failure.
DateTime::modify()
date_modify()

[Alters the timestamp]

Modifies the timestamp of a DateTime object by incrementing or decrementing in a format accepted by strtotime(). Object-oriented style:
DateTime::modify(modification_string);
Procedural style:
date_modify(datetime_object, modification_string);
DateTime::modify(): Returns the DateTime object for method chaining on success; FALSE on failure.
DateTime::getOffset()
date_offset_get()

[Returns the timezone offset]

Returns the timezone offset from UTC in seconds. Object-oriented style:
DateTime::getOffset();
Procedural style:
date_offset_get(DateTimeInterface_object);
Returns the timezone offset in seconds from UTC on success; FALSE on failure.
date_parse_from_format()

[Get info about given date formatted according to the specified format]

Returns an associative array containing information about the given date. date_parse_from_format(format, date); Returns an associative array containing information about the given date.
date_parse()

[Returns associative array with detailed info about given date]

Returns an array containing information about the parsed date. date_parse(date);

[date must be in a format accepted by strtotime()]

Returns an array containing information about the parsed date on success; FALSE on failure.
If date is formatted incorrectly, the element ‘errors’ will contain the error messages.
DateTime::sub()
date_sub()

[Subtracts an amount of days, months, years, hours, minutes, and seconds from a DateTime object]

Subtracts the specified DateInterval from the given DateTime. Object-oriented style:
DateTime::sub(DateInterval);
Procedural style:
date_sub(DateTime, DateInterval);
DateTime::sub(): returns the DateTime object for method chaining on success; FALSE on failure.
date_sun_info()

[Returns an array with information about sunset/sunrise and twilight begin/end]

Returns an array with sun info, specifically: sunrise and sunset [zenith angle = 90°’35]; transit [time when sun is at its zenith]; civil_twilight_begin [zenith angle = 96°, ends at sunrise]; civil_twilight_end [zenith angle = 96°, starts at sunset]; nautical_twilight_begin [zenith angle = 102°, ends at civil_twilight_begin]; nautical_twilight_end [zenith angle = 102°, starts at civil_twilight_end]; astronomical_twilight_begin [zenith angle = 108°, ends at nautical_twilight_begin]; and astronomical_twilight_end [zenith angle = 108°, starts at nautical_twilight_end]. date_sun_info(time, latitude, longitude); Returns an array of elements containing information relating to sunset/sunrise and twilight begin/end on success; FALSE on failure. The values of the array elements are either UNIX timestamps, FALSE if the sun is below the respective zenith for the whole day, or TRUE if the sun is above the respective zenith for the whole day.
date_sunrise()

[Returns time of sunrise for a given day and location]

This function returns the sunrise time for a given day (specified as timestamp) and location. An E_NOTICE will be generated each time a call is made to a DateTime function with an invalid timezone. An E_STRICT or E_WARNING message is generated if using the system settings or the TZ environment variable. date_sunrise(timestamp, format [optional parameter], latitude [optional parameter], longitude [optional parameter], zenith [optional parameter], gmt_offset [optional parameter]);

[format can be represented by the following values: SUNFUNCS_RET_STRING; SUNFUNCS_RET_DOUBLE; and SUNFUNCS_RET_TIMESTAMP.]

Returns the sunrise time in the specified format on success; FALSE on failure. For part of the year inside the polar circles the sun does not rise at all, which is one potential reason why this function might fail.
date_sunset()

[Returns time of sunset for a given day and location]

Returns the sunset time for a given day (specified as timestamp) and location. latitude and longitude default to north and east respectively; pass in a negative value for south and west. Some useful zenith values include: 90°50′ [sunset: sun becomes invisible]; 96° [civil twilight: signifies end of dusk]; 102 ° [nautical twilight: horizon ends being visible at sea]; and 108° [astronomical twilight: sun ends being the source of any illumination]. date_sunset(timestamp, format [optional parameter], latitude [optional parameter], longitude [optional parameter], zenith [optional parameter], gmt_offset [optional parameter]);

[gmt_offset is specified in hours and is ignored if format is represented by SUNFUNCS_RET_TIMESTAMP.]

Returns the sunset time in the specified format on success; FALSE on failure. For part of the year inside the polar circles the sun does not set at all, which is one potential reason why this function might fail.
DateTime::setTime()
date_time_set()

[Sets the time]

Resets the current time of the DateTime object to a different time. Object-oriented style:
DateTime::setTime(hour, minute, second [optional parameter], microseconds [optional parameter]);
Procedural style:
date_time_set(DateTime_object, hour, minute, second [optional parameter], microseconds [optional parameter]);

[second and microseconds default to 0.]

DateTime::setTime(): returns the DateTime object for method chaining on success; FALSE on failure.
DateTime::getTimestamp()
date_timestamp_get()

[Gets the Unix timestamp]

This function gets the Unix timestamp. Object-oriented style:
DateTime::getTimestamp();
Procedural style:
date_timestamp_get(DateTimeInterface_object);.
Returns the Unix timestamp representing the date.

Web design certified by:
Click images for proof of certification.

Exit mobile version