Sunday, March 11, 2012

DateTime Format Codes

Hi everyone (again). I'm having trouble with some sate formats with the convert() function (I'm not finding the correct format code for "YYYY" format). Is it 100?
Sorry for the silly question
Thanks and best regards
Rafael Mauricio Nami
There is no direct style to get just the year format. You can do one of the following:

select cast(year(current_timestamp) as char(4))
, cast(datepart(year, current_timestamp) as char(4))
, convert(char(4), current_timestamp, 112)

No comments:

Post a Comment