PDA

View Full Version : Comparing Dates



mwieting
04-07-2017, 01:20 PM
In my database i have to different date fields. What I want to do is create a vba code that would filter out any entry that has 2 dates that are in the same month. I tried to upload a sample of my data but i am currently getting an error.

HiTechCoach
04-07-2017, 08:21 PM
Welcome! :hi:


Where do you plan to use the VBA code?

You normally filter records using a Query.

To compare Month for any year use:


Month([Date_1]) = Month([Date_2])


To compare month and year try the following:


(Month([Date_1]) = Month([Date_2])) and (Year([Date_1]) = Year([Date_2]))

or


Format([Date_1], "yyyymm") = Format([Date_2], "yyyymm")



On a form you could use:

To compare month and year try the following:


(Month(Me.[Date_1]) = Month(Me.[Date_2])) and (Year([Me.Date_1]) = Year(Me.[Date_2]))

or


Format(Me.[Date_1], "yyyymm") = Format(Me.[Date_2], "yyyymm")

mwieting
04-09-2017, 01:31 PM
Sorry I havent used access in awhile. 18896

HiTechCoach
04-10-2017, 05:47 PM
Without knowing more details of exactly what you are doing I can only give parts to help you. Not a working solution.

What I posted about a query was only the criteria (Where) part of a query.

A query would look something like


Select [MyPrimaryKey], OPENDT, LASTDISBDT from [MyTableWithDates] where (Month(OPENDT) = Month(LASTDISBDT)) And (Year(OPENDT) = Year(LASTDISBDT))

You will need to dd additional fields as needed. You may also need to add additional tables to get the two dates you want to compare.