tim_carter
asked on
Datediff HALF YEAR?? and dateadd
Guys it doesnt work right
declare @StartTime datetime
set @StartTime = '10/01/2008'
SELECT
CASE t2.HowToCharge
WHEN 1 THEN CONVERT(char,DateAdd(m,DAT EDIFF(m,t2 .StartDate ,@StartTim e),t2.Star tDate),101 )
WHEN 3 THEN CONVERT(char,DateAdd(q,DAT EDIFF(q,t2 .StartDate ,@StartTim e),t2.Star tDate),101 )
WHEN 6 THEN CONVERT(char,DateAdd(q,2*D ATEDIFF(q, t2.StartDa te,@StartT ime),t2.St artDate),1 01)
WHEN 12 THEN CONVERT(char,DateAdd(year, DATEDIFF(y ear,t2.Sta rtDate,@St artTime),t 2.StartDat e),101)
END
NextInvoiceDate,
Am i missing something here. The half year doesnt work.
If i set @StartTime = 10/01/2008 And the date in the StartDate is 10/01/2008. NextInvoiceDate, will be 10/01/2008 as it should. But as this should be every half year, the next date should be 04/01/2009 RIGHT? but it isnt, if you change StartTime to 04/01/2009 NextInvoiceDate will be 10/01/2009. But if you change StartTime to 03/01/2009 NextInvoiceDate will be 04/01/2009. What am i doing wrong?
And another thing, how can i handle people going back in time. I mean if the StartTime is smaller than StartDate
declare @StartTime datetime
set @StartTime = '10/01/2008'
SELECT
CASE t2.HowToCharge
WHEN 1 THEN CONVERT(char,DateAdd(m,DAT
WHEN 3 THEN CONVERT(char,DateAdd(q,DAT
WHEN 6 THEN CONVERT(char,DateAdd(q,2*D
WHEN 12 THEN CONVERT(char,DateAdd(year,
END
NextInvoiceDate,
Am i missing something here. The half year doesnt work.
If i set @StartTime = 10/01/2008 And the date in the StartDate is 10/01/2008. NextInvoiceDate, will be 10/01/2008 as it should. But as this should be every half year, the next date should be 04/01/2009 RIGHT? but it isnt, if you change StartTime to 04/01/2009 NextInvoiceDate will be 10/01/2009. But if you change StartTime to 03/01/2009 NextInvoiceDate will be 04/01/2009. What am i doing wrong?
And another thing, how can i handle people going back in time. I mean if the StartTime is smaller than StartDate
There's something missing from the problem definition here ...
You're not just trying to find half a year from the StartTime or half a year from the StartDate ... you're trying to find ... what?
If the start point is clear then adding either 2 quarters or 6 months should get you what you want.
You're not just trying to find half a year from the StartTime or half a year from the StartDate ... you're trying to find ... what?
If the start point is clear then adding either 2 quarters or 6 months should get you what you want.
ASKER
Everymonth i will change the @startdate to the current date. (month). and the field NextInvoiceDate should tell me the date for each client when they should be invoiced. Now the Quarterly, and Yearly and ofcourse monthly works fine. But i cant seem to get the Helf Year working. Do you have an example of how to do that? Because the way i have done it in the example above, will never work.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
dont think it can be done, but thanks for the help guys
ASKER