my requirement is cast the '2013050' date into date in sql
please help
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Feb 21, 2013, 12:42 AM EST
cc represents the century
yy represents the year in that century (0 to 99)
ddd represents the day in that year (1 to 365) or (1 to 366 in a leap year)
As Jignesh said, that's not a supported format in SQL Server.
However, it's fairly easy to convert it into a 'normal' date in C# code if that's any help to you:
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 20, 2013, 5:49 PM EST
hi,
it just look like unvalid date because 7 digit date '2013050' if we part this date year is 2013 month is 05 and date is 0?
it is not possible of 0 date.. :)
you may just refer below link
http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx
it contain conversion of date in different format
hope this will help you.
Mai Hu Na84 reputationPosted Feb 20, 2013, 8:57 PM EST
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 20, 2013, 10:20 PM EST
sorry, but can you please explain what is cc?
and also as you say your date is in ccyyddd format
so your example is '2013050' so here ddd = 050 so i thinkit is not possible.
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 21, 2013, 12:59 AM EST
Thanks Vulpes for given understanding..
Atul try,
Declare @value varchar(7) = '2013050'
select DATEADD(d,CAST(SUBSTRING(@value,5,3) as int),cast(SUBSTRING(@value,1,4) + '-01-01' as date))
here i am assuming first date of year is 1st jan.
it might help you.
VulpesRank #55 · 29.2K reputationPosted Feb 21, 2013, 1:44 AM EST
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 21, 2013, 2:04 AM EST
it must
Declare @value varchar(7) = '2013050'
select DATEADD(d,CAST(SUBSTRING(@value,5,3) as int) - 1, cast(SUBSTRING(@value,1,4) + '-01-01' as date))
thx.