Prakruti Pathik
Prakruti Pathik

Reputation: 392

Query displaying date format only instead of date and time

I am trying to execute a sql query in the date and time format but I am getting only date format as 26-Nov-15. Below is the query?

SELECT to_date((SYSTIMESTAMP - (20/1440)) ,'DD-MON-YYYY HH24:MI:SS')
FROM DUAL

what is that I am doing wrong?

Upvotes: 0

Views: 50

Answers (1)

user330315
user330315

Reputation:

Don't use to_date() on a date value - it makes no sense at all.

It first converts the input date into a varchar which is then converted back to a date which it was to begin with.

If you want to display the result in a formatted way use this:

SELECT to_char((SYSTIMESTAMP - (20/1440)) ,'DD-MON-YYYY HH24:MI:SS')
FROM DUAL

Unrelated, but: I prefer to use an interval to make an expression like the above readable:

SELECT to_char(SYSTIMESTAMP - interval '20' minute,'DD-MON-YYYY HH24:MI:SS')
FROM DUAL

In my opinion interval '20' minute is much easier to understand than 20/1440

Upvotes: 1

Related Questions