Subtract months from the years and months field

FahadTiger

Member
Local time
Tomorrow, 01:48
Joined
Jun 20, 2021
Messages
120
Hi ,Expert
I have 3 field in query as shown ...I have yearNu and monthNub ... and subtractMomonth ..when I enter 15 in subtractMomonth ..the resault is YearNu=18 and MonthNu=11...is there function to do do this
thanks for all
 

Attachments

  • Y.PNG
    Y.PNG
    4.7 KB · Views: 116
When you want to work with dates, you need to work with dates. Do that you have a lot of built in date functions available to you:


DateAdd would be a simple function to use in this instance, however, it works with dates, not numbers like you have. Instead of 2 fields--one for month and one for year, you should store the MonthNu and YearNu in one field that is a date/time field. Do that and Access can easily subtract 15 months from February 1, 2020 to arrive at November 1, 2018.

The alternative is to write your own function to achieve the same thing.
 
Use DateSerial (with fictional day) to convert to date, DateAdd to subtract and Year() and Month te convert to numbers again.
 
Hi ,Expert
I have 3 field in query as shown ...I have yearNu and monthNub ... and subtractMomonth ..when I enter 15 in subtractMomonth ..the resault is YearNu=18 and MonthNu=11...is there function to do do this
thanks for all
I'm not sure I understand the question. Where will you enter the value 15? In the query? And how come the result will equal to 18 and 11, instead of 20 and 2?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom