advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Partners & Affiliates
advertisement
advertisement
Tip of the Day
Rate this item | 0 users have rated this item.
Expertise: Intermediate
Language: PL/SQL
November 22, 2005
Presenting Dates in Varying Formats
Dates are generally a requirement for every application. However, including dates for users across the globe can be tedious, because different people use different formats to read the date.

Oracle has an easy way of presenting the dates to users, in the way they want: the variable NLS_DATEFORMAT.

  • Example 1: The required date format is MM-DD-YYYY.
    Command: ALTER SESSION SET NLS_DATEFORMAT='MM-DD-YYYY'
  • Example 2:
  • The required date format is DD-MM-YYYY.
    Command: ALTER SESSION SET NLS_DATEFORMAT='DD-MM-YYYY'
  • Example 3: The required date format is YYYY-MON-DD.
    Command: ALTER SESSION SET NLS_DATEFORMAT='YYYY-MON-DD'
Because this change is only available only for the current session, everytime you open a session, you may need to set the required date format and from there use it as required.

If you want a certain format to be the default, irrespective of the session, you will need to modify the init.ora file.

Sridhar MS
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.
Please rate this item (5=best)
 1  2  3  4  5
advertisement
advertisement