====== dbDate ====== ~~NOTOC~~ == syntax == string dbDate( string|float|object $timestamp, optional bool $isFieldValue = false ) ===== Description ===== The function ''dbDate()'' accepts a either a Unix timestamp value or a PHP [[https://www.php.net/manual/en/class.datetime.php|DateTime Object]], and returns a database-specific date string. This can then be used in SQL statements. The returned value differs from one database to another. Note that the returned value already includes any required quoting If the passed value is empty, the the string **null** is returned. If the optional argument //**$isFieldValue**// is true, then the passed value is returned unmodified ===== Usage ===== ==== MySQL example ==== /* * Connection to MySQL database assumed */ $date = date('Y-m-d'); $d = $db->dbDate($date); /* * Returns the following string: '2015-07-19' */ $SQL = "SELECT * FROM record WHERE date_field=$d"; ==== Oracle Example ==== /* * Connection to Oracle database assumed */ $date = date('Y-m-d'); $d = $db->dbDate($date); /* * Returns the following string: TO_DATE('2015-07-19','YYYY-MM-DD') */ $SQL = "SELECT * FROM record WHERE date_field=$d";