" . $dfields[0] . "-" . $dfields[1] . "-" . $dfields[2] . " " . $tfields[0] . ":" . $tfields[1] . ":" . $tfields[2] . " ($unixtime sec)
\n"; */ return $unixtime / 86400; } /** * Calculate the number of seconds since January 1, 1970 for a given ISO date * WARNING: Works only for years less than about 2038 * @see mysqldatetoseconds, it_date_mysqltimestamptounix * @param $datetime Date/time in ISO (aka mysql) format: YYYY-MM-DD HH:MM:SS * @return The supplied date as number of seconds since the start of the epoch */ function mysqldatetoseconds($datetime) { $dt = split(' ', $datetime); $dfields = split("-", $dt[0]); $tfields = split(":", $dt[1]); $unixtime = intval(mktime($tfields[0], $tfields[1], $tfields[2], $dfields[1], $dfields[2], $dfields[0])); /* echo "$datetime --> " . $dfields[0] . "-" . $dfields[1] . "-" . $dfields[2] . " " . $tfields[0] . ":" . $tfields[1] . ":" . $tfields[2] . " ($unixtime)
\n"; */ return $unixtime; } /** * Calculate the number of seconds since January 1, 1970 for a given mysql timestamp * (which is in format YYYYMMDDhhmmss). Ignores all non-numerical characters, so this * function can be used as a substitute for mysqldatetoseconds(). * WARNING: Works only for years less than about 2038 * @see mysqldatetoseconds, it_date_unixtomysqltimestamp * @param $ts Date/time in ISO (aka mysql) format: YYYYMMDDhhmmss * @return The supplied date as number of seconds since the start of the epoch */ function it_date_mysqltimestamptounix($ts) { $ts = ereg_replace('[^0-9]+', '', $ts); return intval(mktime(substr($ts, 8, 2), substr($ts, 10, 2), substr($ts, 12, 2), substr($ts, 4, 2), substr($ts, 6, 2), substr($ts, 0, 4))); } /** * Convert the given UNIX timestamp to a mysql timestamp in format YYYYMMDDhhmmss. * WARNING: Works only for years less than about 2038 * @see mysqldatetoseconds, it_date_mysqltimestamptounix * @param $ts Date/time in UNIX format (number of seconds since January 1, 1970) * @return The supplied date as YYYYMMDDhhmmss */ function it_date_unixtomysqltimestamp($ts) { return strftime('%Y%m%d%H%M%S', $ts); } /** * Return the supplied date/time in human-readable Swiss format * WARNING: Works only for years less than about 2038 * @see swisstimestamp, mysqldatetoseconds * @param $datetime Date/time in ISO (aka mysql) format: YYYY-MM-DD HH:MM:SS * @return The supplied date/time formatted as "14.08.1966 06:15" */ function swissdate($datetime) { return strftime("%d.%m.%Y %H:%M", mysqldatetoseconds($datetime)); } /** * Return the supplied UNIX timestamp in human-readable Swiss format * WARNING: Works only for years less than about 2038 * @see swissdate, mysqldatetoseconds * @param $datetime Optional date/time in seconds from the beginning of the epoch (default is now) * @return The supplied date/time formatted as "14.08.1966 06:15" */ function swisstimestamp($datetime = null) { return strftime('%d.%m.%Y %H:%M', isset($datetime) ? $datetime : time()); } ?>