MOnthoffset reversal

Deepmath
Deepmath used Ask the Experts™
on
hi,

 I used this  formula to calculate month offset .Theformula calculates the number of months from JAn 1900.

datediff(month,'01/01/1900',convert(datetime,'01/' + convert(varchar,month) + '/' + convert(varchar,year)))



 in the above formular if the year was 3008 and month was 9 then the monthoffset=1304

Now i want to convert 1304 back to 09/2008..how do i achieve this.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Here you go:
Select Dateadd(Month, 1304 - ((1304/12)*12), Dateadd(Year,(1304/12),'1900-01-01'))
This is if you start year is always 1900-01-01
Hope this helps.
P.
Commented:
try this
SELECT DATEPART(YEAR, DATEADD(MONTH,  monthOffset, '19000101')) AS year, DATEPART(MONTH, DATEADD(MONTH,  monthOffset, '19000101')) AS month 

Open in new window

Author

Commented:
i found it myself

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial