Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert string to date, for use in SQL Server...

Status
Not open for further replies.

gdrenfrew

Programmer
Aug 1, 2002
227
GB
Trying to get a date out of a table, unforunately it is in the format "dd.mm.yyyy". Can someone suggest how I can change this into "dd-Mon-yyy"?

It needs to be in a suitable format for inserting into SQL Server, and I've found that this format works.

I've tried the following:
to_char(translate("DOCDATE",'.','/'),'dd-Mon-yyyy HH24:MI:SS'), but it says it's an invalid number. If I don't use the translate function, to_char doesn't think it's a date.
I'm stuck! :(
 
If your field originally is of DATE data type, you may explicitly convert it to almost whatever you need using TO_CHAR function as in Oracle Dates are stored in some internal format and then are just converted to be displayed according to current NLS settings.

In your case you may use
Code:
TO_CHAR(field, 'dd-Mon-yyy')

If that field is string ([VAR]CHAR[2]), then you may convert it to date and then apply another mask:
Code:
TO_CHAR( TO_DATE(field, 'dd.mm.yyyy'), 'dd-Mon-yyy')

Regards, Dima
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top