MariaDB TIMESTAMP() Function

In MariaDB, TIMESTAMP() is a built-in function that sums all arguments and returns the result as a datetime value.

MariaDB TIMESTAMP() Syntax

This is the syntax of the MariaDB TIMESTAMP() function:

TIMESTAMP(date_or_datetime)

or

TIMESTAMP(date_or_datetime, time)

Parameters

date_or_datetime

Required. A date or datetime expression. Format: YYYY-MM-DD or YYYY-MM-DD HH:MM:SS.

time

Optional. A time value. Format: HH:MM:SS.

If you supply the wrong number of arguments, MariaDB will report an error: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1.

Return value

The MariaDB TIMESTAMP(date_or_datetime) function will return this date_or_datetime as a datetime value. TIMESTAMP(date_or_datetime, time) returns the sum of date_or_datetime and time as a datetime value.

If either argument is NULL, the TIMESTAMP() function will return NULL.

TIMESTAMP() Examples

Example 1 - date value

SELECT TIMESTAMP('2023-01-12');

Output:

+-------------------------+
| TIMESTAMP('2023-01-12') |
+-------------------------+
| 2023-01-12 00:00:00     |
+-------------------------+

Example 2 - Date and time values

SELECT TIMESTAMP('2023-01-12', '10:10:10');

Output:

+-------------------------------------+
| TIMESTAMP('2023-01-12', '10:10:10') |
+-------------------------------------+
| 2023-01-12 10:10:10                 |
+-------------------------------------+

Example 3 - datetime and time values

SELECT TIMESTAMP('2023-01-12 12:00:00', '12:00:00');

Output:

+----------------------------------------------+
| TIMESTAMP('2023-01-12 12:00:00', '12:00:00') |
+----------------------------------------------+
| 2023-01-13 00:00:00                          |
+----------------------------------------------+

Conclusion

In MariaDB, TIMESTAMP() is a built-in function that sums all arguments and returns the result as a datetime value.