Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Date Manipulation
Message
De
06/08/2018 13:53:57
 
 
À
06/08/2018 10:53:50
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Versions des environnements
SQL Server:
SQL Server 2012
Divers
Thread ID:
01661461
Message ID:
01661471
Vues:
39
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?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform