Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have below data in a tableTable1:MM DD YR--- -- ----5 4 2007I need the below output like.Date----------2006-05-26 Thanks for your help in advance
sqldba2k6
Posting Yak Master
176 Posts
Posted - 2007-06-14 : 17:35:17
Please ignore my previous postBelow is correct oneI have below data in a tableTable1:MM DD YR--- -- ----5 4 2007I need the below output like.Date----------2007-05-04 Thanks for your help in advance
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2007-06-14 : 17:44:07
Here are two ways:
DECLARE @T TABLE (MM int, DD int, YR int)INSERT @TSELECT 5, 4, 2007 SELECT CAST(CAST(YR AS VARCHAR) + RIGHT('0' + CAST(MM AS VARCHAR), 2) + RIGHT('0' + CAST(DD AS VARCHAR), 2) AS DATETIME) ,DATEADD(DAY, DD - 1, DATEADD(MONTH, MM - 1,DATEADD(YEAR, YR - 1900, 0)))FROM @T
quote:Originally posted by sqldba2k6 Please ignore my previous postBelow is correct oneI have below data in a tableTable1:MM DD YR--- -- ----5 4 2007I need the below output like.Date----------2007-05-04 Thanks for your help in advance
Another way to do
select mm, dd, yr, dateadd(day,dd-1,dateadd(month,mm-1,dateadd (year,yr-1900,0))) as DateInQuestion from @t
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2007-11-12 : 17:47:00
SELECT DATEADD(MONTH, YR * 12 - 22801 + MM, DD - 1)E 12°55'05.25"N 56°04'39.16"