SQL TIMESTAMP() Function – All you need to know!

Filed Under: SQL

Hey, all. In our series of SQL DATE and TIME functions, in this article, we will learn the SQL TIMESTAMP() function in detail.

The SQL DATE and TIME functions enable us to deal date-time data. Moreover, using these functions, we can extract a portion of the date and time from the datetime expressions.

So, let us begin with understanding about the working of TIMESTAMP() function.

What is SQL TIMESTAMP() function?

TIMESTAMP represents the date and time value of a particular record at a particular event.

The TIMESTAMP() function enables us to represent and return a datetime expression out of a date or datetime expression. Moreover, it accepts the date expression and adds time value to it and returns the datetime expression.

Having understood the working of TIMESTAMP() function, let us now focus on the structure of the same.

Syntax of TIMESTAMP() function

The TIMESTAMP() function accepts the date or datetime expression as an argument and it returns the datetime value out of it as output.


TIMESTAMP(date or datetime expression)

The SQL TIMESTAMP() function also even accepts two date or datetime values as arguments to return the output as shown below:

The first argument gets added to the second argument and then the resultant datetime value is returned.


TIMESTAMP(expression1, expression2)

Now, let us implement the same through the below examples.

Examples of TIMESTAMP() function

In the below example, we have used the SELECT statement passed a date expression to the timestamp() function.

SELECT TIMESTAMP("2020-07-28")

The function adds the default time expression value to it and returns the datetime value.



Now, we have passed a datetime expression to the function and the functions returns a datetime value out of it.

SELECT TIMESTAMP("2020-07-28 20:12:12")



In the below example, we have passed a datetime expression and a time expression to the TIMESTAMP() function.

SELECT TIMESTAMP('2020-07-28 20:10:10','1:50:50');

It adds the time values of both the expressions and returns the datetime value of it.




By this, we have come to the end of this topic. Feel free to comment below, in case you come across any question. For more such posts related to SQL, do visit SQL JournalDev.

Till then, Happy Learning!!


Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors