Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date Manipulation
Message
From
06/08/2018 15:59:52
 
 
To
06/08/2018 13:53:57
General information
Forum:
Microsoft SQL Server
Category:
Scripting
Environment versions
SQL Server:
SQL Server 2012
Miscellaneous
Thread ID:
01661461
Message ID:
01661474
Views:
38
Last (bracketed) word you should focus on - the wait window examples should give you pause to code something based on looping, as that could automatically result in errors when dates with day>27 enter the system...

At least make sure that you get in writing that dates > 27 will never be worked upon ;-)))


>The start date has always been the first of the month so thankfully those things haven't bitten me in this system (yet).
>
>>I hate date math! At least, before coding, make sure you and all others agree upon same definitions.
>>For that I find it better to spell out the math at the end of a month: verbal test cases, resulting in code equivalent to
> >
>>
ld30 = gomonth(date(2018,1,30), 1)
>>ld31 = gomonth(date(2018,1,31), 1)
>>? ld30=ld31
>>?
>>? gomonth(gomonth(date(2018,1,31), 1), -1)
>>?
>>? DAY(gomonth(date(2018,1,31), 1)) - DAY(gomonth(date(2018,1,24), 1))
>>WAIT WINDOW gomonth(gomonth(date(2018,1,31), 1), 1)
>>WAIT WINDOW gomonth(date(2018,1,31), 2)
>>

>>
>>can start heated discussions, involving calls to legal in insurance - been there, done that ;-)))
>>But it is best to clarify before coding, NOT when testing ;-)
>>Another way to put it:
>>date math is one of the very few places test driven development makes sense to this old war horse ;-)
>>
>>And my mind will probably never understand why we have always 7 months with 31 days instead of 5 months with 31 days in normal years and 6 months with 31 days in leap years with the rest all having 30 days.
>>
>>>Hi,
>>>I have a situation where an Insurance Plan can start on a user defined date (say 1st February 2010) and it has a period length of a user defined number of months (say 12 months).
>>>If a user makes a claim in March 2018, the start of the relevant period is 1st February 2018. Or if the claim was on 10th January 2018, the start of the relevant period would be 1st Feb 2017.
>>>
>>>I worked out this start date with this code in Visual FoxPro:
>>>
>>>
			DO WHILE m.pdService > GOMONTH(m.tdPeriodStart, m.tnPeriodLength)
>>>				m.tdPeriodStart = GOMONTH(m.tdPeriodStart, m.tnPeriodLength)
>>>			ENDDO
>>>
>>>I am now trying to write a Stored Procedure which has to calculate this date, is there any easy way to do this in TSQL? Or shall I just apply a similar LOOP and keep adding the period Length to the start date?
Previous
Reply
Map
View

Click here to load this message in the networking platform