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 in insert() or update()
  • $db->currentDate() – returns Y-m-d, Y-m-d H:i:s, or timestamp depending on mode
  • $db->currentDateOnly() – shortcut for Y-m-d
  • $db->currentDatetime() – shortcut for Y-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 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.

See Also