count days

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm working with a project which needs to count number of days in the month. How can I do it?
And, how can I count the days from the date I enter to the end of the month? For example, if the date is 14/01/2004, the query will show 18 (number of days from 14/01/2004 to 31/01/2004).
 
Daryl,

Because the number of days in a month is variable, you can work from
"the day before the 1st of next month". For example, number of days
until the end of this month:
DateAdd("m",1,Date())-Day(Date())-Date()
Number of days in this month:
Day(DateAdd("m",1,Date())-Day(Date()))

- Steve Schapel, Microsoft Access MVP
 
Last day of month

DateSerial(Year(SomeDate),Month(SomeDate)+1,0)

Count of days in a month
Day(DateSerial(Year(SomeDate),Month(SomeDate)+1,0))

Difference between a date and the end of the month for that date
DateDiff("d",SomeDate,DateSerial(Year(SomeDate),Month(SomeDate)+1,0))

To get the results you want, you may need to add 1 to the above outcome OR just
change the 0 in the dateserial to a 1
DateDiff("d",SomeDate,DateSerial(Year(SomeDate),Month(SomeDate)+1,1))
 
John,

The reason why I wouldn't have used this approach (well, one of the
reasons... I still prefer my idea! :-) was that I didn't expect it
would handle the current date in December. But anyway, I now see that
it does. Lovely.

- Steve Schapel, Microsoft Access MVP
 
Back
Top