Date Helpers
PDOdb provides a few convenient helper methods to generate current date/time values for use in INSERT, UPDATE, or WHERE clauses.
These values are formatted according to MySQL expectations and are timezone-safe.
Available Methods
$db->now()– returns['[F]' => 'NOW()'], safe to use ininsert()orupdate()$db->currentDate()– returnsY-m-d,Y-m-d H:i:s, ortimestampdepending on mode$db->currentDateOnly()– shortcut forY-m-d$db->currentDatetime()– shortcut forY-m-d H:i:s$db->currentTimestamp()– returns current UNIX timestamp
Example: insert current timestamp
$data = [
'username' => 'admin',
'created_at' => $db->now(), // uses NOW() function safely
];
$db->insert('users', $data);
Example: compare with current date in WHERE
$db->whereDate('created_at', $db->currentDateOnly(), '>=');
$rows = $db->get('orders');
Note: You can use
now() directly inside insert(), update() or replace(). It automatically expands to a safe SQL expression like NOW() using the [F] function placeholder.
Why not use
While PHP’s native
Use
date() directly?While PHP’s native
date() is fine, these helper methods make sure your formatting is consistent and query-safe.Use
currentDatetime() instead of manually calling date('Y-m-d H:i:s') everywhere.