Rick
Rick

Reputation: 1569

SQL date format - producing different result

I have a table Cdata that has DOB column and the column value are as below:

'1945-01-01 00:00:00.000' 

I am formatting the above to 'YYYYMMDD' format as below:

select  format(c.dob,'yyyymmdd') from dbo.Cdata c where c.cid='12345'

I am getting not getting the output as expected.

Desired output:'YYYYMMDD' format: '19450101'

Rexter link: http://rextester.com/NXBNZC17084

Any help?

Upvotes: 0

Views: 47

Answers (1)

DB101
DB101

Reputation: 633

You need to capitalise the mm to MM in your format. As it is, it will return the minute portion of your date string. Try the following

DECLARE @A DATETIME = '1945-01-01 00:00:00.000' 
select  format(@A ,'yyyyMMdd') 

Upvotes: 2

Related Questions