Extracting only date from a datetime field

In Oracle, to extract only the date from a datetime field, use the code below:

 select * from table_name where trunc(field_name) < = '2013-08-01'; 

Suppose your field UPDATE_DTTM has datetime stamp of a transaction – say ‘2013-08-01 02:30:31’

 select * from table_name where UPDATE_DTTM < = '2013-08-01'; 

would not return any rows. Because, by default in Oracle, ‘2013-08-01’ represents ‘2013-08-01 00:00:00’

But,

 select * from table_name where trunc(UPDATE_DTTM) < = '2013-08-01'; 

would return a row, since only the date is being compared.

Have fun 🙂

 

Advertisements

About Manikandan Surendren

A PeopleSoft Techno-functional Consultant. An engineering graduate in Computer Science. Technology Enthusiast. Movie freak. Gadget geek.
This entry was posted in Oracle, PeopleSoft, SQL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s