/** * Returns a valid SQL-formatted date for a current database. * Examples: * sqlDate(true, 2007, 2, 3) returns '2007-02-03'. * sqlDate(false, 2007, 2, 3) returns OA_Dal::noDateValue(). * sqlDate(true, 2007, '-', 3) returns OA_Dal::noDateValue(). * * @static * @param boolean $validDate If true, the function will try to generate * a valid date. Otherwise, it will ignore other arguments and just return * an 'empty' date for this database. * @param integer $year * @param integer $month Month number from 1 to 12 * @param integer $day Day number from 1 to 28/29/30/31 * @return string If $validDate is true and all other parameters are valid * integers, constructs a proper sql date string. If any of the $year, * $month, $day is '-' or $validDate is false, returns a valid 'empty' * date string for the database. */ function sqlDate($validDate, $year, $month, $day) { if (!$validDate || $year == '-' || $month == '-' || $day == '-') { return OA_Dal::noDateValue(); } $month = OA_Dal::to2digitFormat($month); $day = OA_Dal::to2digitFormat($day); return "{$year}-{$month}-{$day}"; }