Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 convert datetime

Author  Topic 

smorty44
Yak Posting Veteran

93 Posts

Posted - 2007-08-29 : 16:45:17
I'm having trouble converting a date of birth field, datatype int from yyyymmdd to mmddyyyy.

select 'DOB' = Convert(char(10), pat_dob, 101) from patfile

what am I missing?

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-08-29 : 16:54:00
Do you receive any error?

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

smorty44
Yak Posting Veteran

93 Posts

Posted - 2007-08-29 : 17:07:57
I'm not getting an error but the date is not converting to the format 'mmddyyyy' instead remaining the same at 'yyyymmdd'.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-08-29 : 17:32:13
DateTime values in SQL Server do not have format. They are just values. You format the data when you retrieve it from the database at your client, report, or whatever your front end is.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-30 : 01:21:09
Always use proper datatypes!

SELECT REPLACE(CONVERT(CHAR(8), CAST(CAST(pat_dob AS CHAR(8)) AS DATETIME), 101), '/', '')



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -