Default as days in month

D

dimpie

I want to assign total number of days in the current month to a text field.
Please let me know if there is a function that does that.

Thank you!
 
R

Rick Brandt

dimpie said:
I want to assign total number of days in the current month to a text
field. Please let me know if there is a function that does that.

Thank you!

Format(DateSerial(Year(Date()), Month(Date()) + 1, 0), "d")
 
D

Douglas J. Steele

Rick Brandt said:
Format(DateSerial(Year(Date()), Month(Date()) + 1, 0), "d")

Or Day(DateSerial(Year(Date()), Month(Date()) + 1, 0), "d") or DatePart("d",
DateSerial(Year(Date()), Month(Date()) + 1, 0))

I prefer either of these to using Format, since Format returns a string, and
there requires coercion back to an integer, where as the Day and DatePart
functions return a number.
 
R

Rick Brandt

Douglas said:
Or Day(DateSerial(Year(Date()), Month(Date()) + 1, 0), "d") or
DatePart("d", DateSerial(Year(Date()), Month(Date()) + 1, 0))

I prefer either of these to using Format, since Format returns a
string, and there requires coercion back to an integer, where as the
Day and DatePart functions return a number.

Good point and one which I had considered until I saw that the OP specified
that he wants the value to go into a "text field". In most cases though you
are correct that a numeric value would be the most likely result desired.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top