formulize_timeValueAsISO( $value, $formats = null )

Location

/modules/formulize/include/functions.php

Description

Turns a time into the 24-hour form HH:MM:SS, such as 13:30:00, whatever format it was shown in.

Time elements show times in your site’s 12-hour or 24-hour time format, which you can change under Date & time formats in the settings. A time in a derived value, or from getValue, comes in that format. Use this function on it before you work out the time between two times, or compare times, so your code keeps working if the format changes.

Parameters

$value - the time, as a time element shows it, such as 1:30pm, or as it’s stored, such as 13:30
$formats - Optional. The time formats to read the time in, as one PHP date format or an array of them, tried in order. By default, your site’s 12-hour format and then its 24-hour format.

Return Values

Returns the time as HH:MM:SS.

Returns the value unchanged if it isn’t a time in any of the formats, such as when it’s blank.

Examples

// a derived value: the minutes between the times in the shift_start and shift_end elements
$start = formulize_timeValueAsISO($shift_start);
$end = formulize_timeValueAsISO($shift_end);
if($start AND $end) {
    $value = (strtotime("2000-01-01 $end") - strtotime("2000-01-01 $start")) / 60;
}