By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

Formatting sysdate

rsrinivasan
100+
P: 221
Hi,

When i Execute this query, I got the result as 29-MAY-07
Expand|Select|Wrap|Line Numbers
  1. select sysdate from dual;
But i want 29-MAY-2007.

What is the query for it?

Thanks,
May 29 '07 #1
Share this Question
Share on Google+
5 Replies


chandu031
Expert
P: 78
Hi,

When i Execute this query, I got the result as 29-MAY-07
Expand|Select|Wrap|Line Numbers
  1. select sysdate from dual;
But i want 29-MAY-2007.

What is the query for it?

Thanks,
Hi,

It's a pretty straight forward query:
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT TO_CHAR(SYSDATE,'DD-MON-YYYY') FROM DUAL
  3.  
  4.  
Cheers!
May 29 '07 #2

rsrinivasan
100+
P: 221
Hi,

It's a pretty straight forward query:
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT TO_CHAR(SYSDATE,'DD-MON-YYYY') FROM DUAL
  3.  
  4.  
Cheers!
Ok. Now it is working. But i need date type not char type. For that what to do?

Thanks,
Srinivas r.
May 29 '07 #3

chandu031
Expert
P: 78
Ok. Now it is working. But i need date type not char type. For that what to do?

Thanks,
Srinivas r.
Hi,

You can still use it as a date field. Try inserting to_char(sysdate,'dd-mon-yyyy')
into a date field in a table and you will come to know.
Anyways the other method of changing the date format is to alter the default format in sqlplus:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY';
  3.  
  4.  
This changed format will hold good for the current session and is generally used during file loads.

Hope this helped...
May 29 '07 #4

rsrinivasan
100+
P: 221
Hi,

You can still use it as a date field. Try inserting to_char(sysdate,'dd-mon-yyyy')
into a date field in a table and you will come to know.
Anyways the other method of changing the date format is to alter the default format in sqlplus:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY';
  3.  
  4.  
This changed format will hold good for the current session and is generally used during file loads.

Hope this helped...
Hi,
When i am using to_char() function, it converts date type to char type. So im getting error in code behind.
Then i do not want to set as NLS_DATE_FORMAT = 'DD-MON-YYYY'.
Because some times i need some other format.

Plz say any other suggestion.

Thanks,
Srinivas r.
May 30 '07 #5

chandu031
Expert
P: 78
Hi,
When i am using to_char() function, it converts date type to char type. So im getting error in code behind.
Then i do not want to set as NLS_DATE_FORMAT = 'DD-MON-YYYY'.
Because some times i need some other format.

Plz say any other suggestion.

Thanks,
Srinivas r.
Hi rsrinivasan,

I guess you are comparing this formatted date with some other date field. If yes then it makes sense to format even that field before doing the actual comparison. For example if say a date variable v_date holds sysdate and you want to compare this then you can do:

Expand|Select|Wrap|Line Numbers
  1. SELECT 1 FROM DUAL WHERE TO_CHAR(V,'DD-MON-YYYY') = TO_CHAR(SYSDATE,'DD-MON-YYYY')
  2.  
If your requirement is something else and then please do let me know.

Cheers!
May 30 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.