Query Logic

Novice1

Registered User.
Local time
Today, 14:53
Joined
Mar 9, 2004
Messages
385
I have a date field [RNLTD]; I have a number field [TourLength], which represents the number of months.

What I need to do is calculate a new date by adding the number of months in [TourLength] to the date field [RNLTD]

What I did was take [TourLength] and multiply it by 30, then I added the result to [RNLTD]. The problem is that some months don't have 30 days so my result is wrong.

What is the correct syntax? Thanks
 
Not sure exactly what you are trying to do but this will add a number to the months from the TourLength

RNTLD = DateAdd("M", [TourLength], [RNTLD])

I.e. if you had today's date and the TourLength was three months, then RNTLD would be 5/27/2017.

If you wanted to add the number of days then

RNTLD = DateAdd("D", [TourLength], [RNTLD]) where TourLength was the length of the tour in days.
 
I have a date field [RNLTD]; I have a number field [TourLength], which represents the number of months.

What I need to do is calculate a new date by adding the number of months in [TourLength] to the date field [RNLTD]

I strongly suspect you have a less than ideal data structure. Generally, incrementing or decrementing values in a field is a notoriously unreliable way to manage data. It is prone to getting screwed up in an unrecoverable way because it is actually wiping information.

Best practice leaves the initial data alone and records dated transactions in another table (probably something like "Tours" in your database). The current values are calculated as required by summing the transactions and adding to them to the initial figure. This way the current value can be verified and also retrieved for any time in the past.

Often the initial figure can simply be included in the transactions table as a special type of entry.

Without knowing more about your database it is hard to be more specific.
 

Users who are viewing this thread

Back
Top Bottom