-3

When i executed the below query in Oracle

select TO_CHAR((CURRENT_DATE),'DD-Mon-YYYY HH24:MI:SS')  from dual;
 O/P : 04-Mar-2014 14:25:14

I would like to select current date only without current time as below

select TO_CHAR(trunc(CURRENT_DATE),'DD-Mon-YYYY HH24:MI:SS')  from dual;
O/P  :  04-Mar-2014 00:00:00

To achieve the only way is to apply function trunc() on the query? Is there any another way?

Edit : Thanks for your ans.Can it be done without any function?(wihout using to_char or trunc)
{sorry for missing this info}

1
  • Can someone explain me why i received downvotes for this question.Is it a trivial question?
    – abc
    Mar 4, 2014 at 9:35

4 Answers 4

2

The answer is simply no, there is no function that only gets the date part of the date / time (even current_date or sysdate are functions after all).

You should always use trunc to get the current date, without the time.

It isn't necessary to do a trunc and a to_char together. Keep to_char and don't specify the time part.

This is sufficient:

To get the date as varchar:

select TO_CHAR(CURRENT_DATE,'DD-Mon-YYYY')  from dual

To get the date as date, with the time part as 00:00:00:

select trunc(CURRENT_DATE)  from dual
0
1

You can do this:

select TO_CHAR(CURRENT_DATE,'DD-Mon-YYYY')||' 00:00:00'  from dual;
1
  • 2
    that's not, what OP asked
    – Alexander
    Mar 4, 2014 at 9:02
1

there is also EXTRACT function which can be used like that:

SELECT extract(DAY FROM sysdate)
||'-' ||
extract(MONTH FROM sysdate) 
|| '-' || extract(YEAR FROM sysdate) 
FROM dual;

result: 4-3-2014

-1

Use This Query...

select (TO_CHAR(TRUNC(CURRENT_DATE),'DD-Mon-YYYY HH24:MI:SS'))  from dual
1
  • 2
    How is that different from what was shown in the question, apart from the extra and unnecessary set of parentheses?
    – Alex Poole
    Mar 4, 2014 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.