Access 2003/2007 Date Calculations

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

What is the best way to calculate the number of days in a year based upon
year of an entered date? If I have a field with 06/30/1999 what would be the
best/easiest formula for calculating the number of days in 1999.
Thanks
 
Frank said:
What is the best way to calculate the number of days in a year based upon
year of an entered date? If I have a field with 06/30/1999 what would be the
best/easiest formula for calculating the number of days in 1999.
Thanks

Calendar.IsLeapYear or Calendar.GetDaysInYear should work.

DateTime dt = DateTime.Parse("06/30/1999");
GregorianCalendar gc = new GregorianCalendar();
Console.WriteLine(gc.GetDaysInYear(dt.Year));
 
Function NumDays(ByVal DateToUse as Date) As Long
'lNumDays contains the number of days in the year given in #06/30/1999#

Dim lNumDays as Long

lNumDays = CLng(CDate("01/01/" & Year(#06/30/1999#)+1) - CDate("01/01/" &
Tear(#06/30/1999#)))

NumDays = lNumDays

End Function
 
Or, if you prefer code that actually works, use this:

Function NumDays(ByVal DateToUse as Date) As Long
'lNumDays contains the number of days in the year given in #06/30/1999#

Dim lNumDays as Long

lNumDays = CLng(CDate("01/01/" & Year(DateToUse)+1) - CDate("01/01/" &
Tear(DateToUse)))

NumDays = lNumDays

End Function
 
Back
Top