How to calculate a leap year and using julian date. Access 2007

ITguy1981

Registered User.
Local time
Yesterday, 22:11
Joined
Aug 24, 2011
Messages
137
I have two date fields. One "Date Sent" the other "Next Due Date". I've been asked to just take out the "Next Due Date" field so user's don't have to type it and just basically add a text box that will display the date equal to "Date Sent" + 3years - 1day. However, I began to think. what about leap years? I've found some information on Julian dates, but i'm not sure really how use it to get my result. I'm currently using Access 2007.
 
Here's what Alansidman is talking about:
Code:
Private Sub Date_Sent_AfterUpdate()
 If Nz(Me.Date_Sent, "") <> "" Then
  Me.Next_Due_Date = DateAdd("yyyy", 3, Me.[Date Sent]) - 1
 Else
  Me.Next_Due_Date = Null
 End If
End Sub
Note that you really should not have Spaces in Object/Control names in Access. They require special handling and can create problems!

When you use the Control Name

Date Sent

Access' Code Module changes it to

Date_Sent

And referring to it, in code, requires using Square Brackets:

Me.[Date Sent]

Linq ;0)>
 
Thank you Alanidsman. I started with your post first and used DateAdd. I just hope it will calculate for the leap year. So far it's working. Here is the code I used.

=DateAdd("yyyy",3,[FieldName])-1

I was able to get my ([Date Sent] + 3yrs) - 1 day using that.
 
And to ease your mind, the Access Date-related functions do, indeed, take leap year into account!

Linq ;0)>
 
BTW:
The date calculations in Access use modern Gregorian dates projected back into time periods where different calendars were in use.

For instance the following expression returns 12 even though September 2nd was followed immediately by September 14th in 1752 throughout England and its colonies at the time (including what is now USA).

DateDiff("d",#9/2/1752#,#9/14/1752#)

A system that allowed for the actual historical usage in various countries would be incredibly complex.

Dates preceding the conversion to the Gregorian calendar may need to be adjusted depending on the source. Various locations implimented this change between 1582 and 1929.
 

Users who are viewing this thread

Back
Top Bottom