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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert CHARACTER to Date

Status
Not open for further replies.

vladab

Programmer
Aug 13, 2002
13
US
I am trying to convert a field of CHARACTER(8) data type into Date format 'yyyy-mm-dd'. The following query produce 2665 (Invalid date) error :

select cast('20041101' as date format 'yyyy-mm-dd')
from table_name

Please advice how to fix this error.

Vlada


 
I think that select cast('20041101' as date format 'yyyymmdd') would give a better result.
 
Yes. I already changed it to the way you are suggesting and it worked.

Thank you.
 
How about this:

select cast(cast('20041101' as date format 'yyyymmdd') as date format 'yyyy-mm-dd');

*** Query completed. One row found. One column returned.
*** Total elapsed time was 1 second.

'20041101'
----------
2004-11-01
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top