SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 DAte conversion
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Jbalbo
Starting Member

10 Posts

Posted - 02/14/2013 :  13:35:12  Show Profile  Reply with Quote
Sorry if its in the wrong place

Getting a copnversion error on this
DECLARE @FISCALDATE DATE
DECLARE @ENDDATE DATE

set @ENDdate = '02/01/2012'

SELECT CASE
WHEN datepart(MM,@ENDdate)<= 6
THEN
CONVERT(datetime, '01-' + '07-'+ (DATEPART(YY, @ENDDATE) -1), 103)
--DATEPART(YY, @ENDDATE) -1
ELSE
CONVERT(datetime, '01-' + '07-'+ (DATEPART(YY,@ENDDATE)), 103)

END AS fiscalDATE


BTW what Im trying to do is look at a paramter date (Enddate) then calculate the fiscal year start date from it

Thanks IN Advance
Joe

James K
Flowing Fount of Yak Knowledge

3638 Posts

Posted - 02/14/2013 :  14:10:01  Show Profile  Reply with Quote
DECLARE @FISCALDATE DATE
DECLARE @ENDDATE DATE

SET @ENDdate = '02/01/2012'

SELECT CASE 
            WHEN DATEPART(MM, @ENDdate) <= 6 THEN CONVERT(DATETIME, '01-' + '07-' + CAST((DATEPART(YY, @ENDDATE) -1) AS CHAR(4)), 103) 
                 --DATEPART(YY, @ENDDATE) -1
            ELSE CONVERT(DATETIME, '01-' + '07-' + CAST((DATEPART(YY, @ENDDATE) -1) AS CHAR(4)), 103)
       END AS fiscalDATE
But it might be simpler to do it this way:
DECLARE @ENDDATE DATE

SET @ENDdate = '02/01/2012'

SELECT DATEADD(mm,(DATEDIFF(mm,0,@ENDdate)-6)/12*12+6,0) AS fiscalDate
Go to Top of Page

Jbalbo
Starting Member

10 Posts

Posted - 02/14/2013 :  16:32:01  Show Profile  Reply with Quote
That is much nicer way than I was thinking

Thanks
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3638 Posts

Posted - 02/14/2013 :  18:47:04  Show Profile  Reply with Quote
You are very welcome - glad to help.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000