From 274daa6eb8befda71e19a4b7b33c275424996721 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Sun, 1 Feb 2009 06:24:37 +0100 Subject: [PATCH] [svn r18108] Added api_get_datetime() to make it easy to use app-wide the PHP time() function instead of the MySQL NOW() function (see new coding conventions) --- main/inc/lib/main_api.lib.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index dcf9b1678c..52333945ee 100644 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -1642,6 +1642,7 @@ function api_not_allowed($print_headers = false) { ============================================================================== */ /** + * Gets a UNIX timestamp from a MySQL datetime format string * @param $last_post_datetime standard output date in a sql query * @return unix timestamp * @author Toon Van Hoecke @@ -1655,6 +1656,15 @@ function convert_mysql_date($last_post_datetime) { $announceDate = mktime($hour, $min, $sec, $month, $day, $year); return $announceDate; } +/** + * Gets a MySQL datetime format string from a UNIX timestamp + * @param int UNIX timestamp, as generated by the time() function. Will be generated if parameter not provided + * @return string MySQL datetime format, like '2009-01-30 12:23:34' + */ +function api_get_datetime($time=null) { + if (!isset($time)) { $time = time();} + return date('Y-m-d H:i:s', $time); +} /** * Gets item visibility from the item_property table