Oracle Database

Oracle SYSDATE

In this tutorial, we are going to break down one of the most simplistic yet convenient functions in Oracle databases.

Working with dates and date values in databases is nothing to take lightly. This is because you will often encounter the date values across all your data. Hence, having simple tools and helpers in your database is a heavy feature.

Oracle SYSDATE Function

The SYSDATE function in Oracle allows you to fetch the current date and time from the host system where the Oracle server is installed and running.

This is a very convenient function as it can allow you to quickly insert the timestamp information in a column, denoting when the changes to the row have occurred.

Function Syntax:

The SYSDATE function is effortless and does not require arguments.

The following shows the syntax for the sysdate function call:

SYSDATE

As mentioned, the function returns the current date and time from the host system. The resulting value is the DATE data type with the specified format in the NLS_DATE_FORMAT parameter.

Function Usage Illustration:

Although the function is simple and easy to understand, let us provide some basic examples to demonstrate how the function works.

select to_char(sysdate, 'DL') as long_date from dual;

The provided query uses the to_char function to convert the current date into a long format. The result is as follows:

LONG_DATE
---------------
"Thursday, December 24, 2022"

If you do not want to use the long date format, you can use the format as shown in the following:

select to_char(sysdate, 'YYYY-MM-DD HH:MI:SS') as time_stamp from dual;

Output:

TIME_STAMP
----------------------
2022-12-24 06:35:15

We can also perform a quick date arithmetic using the sysdate function and the given interval.

For example, to determine the time in the next 10 hours from now, we can run the following command:

select to_char(sysdate +10/24, 'YYYY-MM-DD HH24:MI:SS') from dual;

Outcome:

NEXT
-----------------
2022-11-24 16:42:12

Conclusion

This concise tutorial describes how to use the sysdate function in Oracle databases to fetch the current date and time from the host system.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list