SYSDATE Function - Oracle to MySQL Migration

In Oracle, the SYSDATE function returns the current date and time for the database server's host OS at the statement execution time.

In MySQL, you can use the NOW() and SYSDATE() functions (parentheses are required), which also include the time.

Note that MySQL NOW() returns the current date and time at the statement execution time, while SYSDATE() returns the time at which the function executes.

Oracle:

  ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';
 
  -- Get the current date and time
  SELECT SYSDATE FROM dual;
  /* 2025-04-09 19:24:55 */

MySQL:

  -- Get the current date and time
  SELECT NOW();
  /* 2025-04-09 19:24:55 */

Execution Time in Oracle

Oracle returns the current date and time at the statement execution time:

Oracle:

  WITH FUNCTION SLEEP_SYSDATE(i NUMBER)
  RETURN DATE IS
  BEGIN
    DBMS_SESSION.SLEEP(i);
    RETURN SYSDATE;
  END;
  SELECT SYSDATE, SLEEP_SYSDATE(3), SYSDATE FROM dual
  UNION ALL
  SELECT SYSDATE, SLEEP_SYSDATE(3), SYSDATE FROM dual;
  /

Result:

SYSDATE SLEEP_SYSDATE(3) SYSDATE
2025-04-09 19:29:05 2025-04-09 19:29:08 2025-04-09 19:29:05
2025-04-09 19:29:05 2025-04-09 19:29:11 2025-04-09 19:29:05

You can observe that all 4 calls of SYSDATE in the query returned the same result, while 2 calls of SYSDATE in the user-defined function returned different results (after a delay).

Execution Time in MySQL

In MySQL, NOW() returns the current date and time at the statement execution time, while SYSDATE() returns the time at which the function executes.

MySQL:

  -- Get the current date and time multiple times with a delay in the same query
  SELECT NOW(), SYSDATE(), SLEEP(3), NOW(), SYSDATE();

Result:

NOW() SYSDATE() SLEEP(3) NOW() SYSDATE()
2025-04-09 19:43:00 2025-04-09 19:43:00 0 2025-04-09 19:43:00 2025-04-09 19:43:03

You can observe that NOW() returned the same value, while SYSDATE() returned different values.

Column Default in MySQL

Oracle allows you to use SYSDATE in a column default:

Oracle:

  CREATE TABLE t1 (c1 DATE DEFAULT SYSDATE);
  /* Table created. */

In MySQL, you can use NOW() only in a colunm default, SYSDATE() is not allowed:

MySQL:

  -- SYSDATE() is not allowed in DEFAULT
  CREATE TABLE t1 (c1 DATETIME DEFAULT SYSDATE());
  /* ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
      corresponds to your MySQL server version for the right syntax to use near 'SYSDATE())' at line 1 */
 
  -- NOW() can be used in DEFAULT   
  CREATE TABLE t1 (c1 DATETIME DEFAULT NOW());
  /* Query OK, 0 rows affected */

For more information, see Oracle to MySQL Migration.