Sunday, October 31, 2010

Query to display timestamp along with date component

As most of us are aware what a Sysdate Function performs , it does return a DATE value when you query the current system date . The Sysdate is a powerful function used very often when you want to consider the system date in various coding practices.If one wants the function to return a immediate next days date then just add a 1 to the sysdate as ( sysdate + 1 ) .This will return the immediate next day's date.

Usage : Select sysdate from dual ;

Coming to the Sql query to see the time stamp component , you need to convert the sysdate format into character specifying what format of date and time you want to see.

Solution : Select  to_char ( sysdate , ' DD-MON-YYYY HH24:MI:SS ' )  from  dual ;

The result would be similar to this :


The Sysdate includes the timestamp component also but while displaying it only shows the date component and when to convert that using to_char function you could see the time component also.

To exclude the time component from sysdate function ,

use - Trunc ( sysdate )
The above function truncates the time component and returns only date component .

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails
Make Money Blogging