Friday, September 17, 2004

Calculating the first and last day of the month

Ever needed to calculate the first and last day of the month? Here's an expression that can be used in Access:

DateSerial(Year(Now), Month(Now) + 1, 0) - Last day of month
DateSerial(Year(Now), Month(Now), 1) - First day of month

15 comments:

Lorence said...

oh, that's so pretty. Thank you!

Lorence
LorencesKitchen.blogspot.com
LorenceSing.com

Anonymous said...

Wicked. Thanks a lot for that.

Robin Cooper said...

Thanks for posting this...Saved me tons of time.

Clear Rift said...

Solved a million problems and saved me so much time! Thank you!

Samson J. Loo said...
This comment has been removed by the author.
Samson J. Loo said...

The coolest thing about this is the fact this same syntax works in SQL Server Reporting Services 2008 for specifying the default values for parameters in terms of dates. I used this exact same syntax to find the first day of the month and the last day of the month and it worked nicely.

Cheers to you!

Anonymous said...

THANK YOU!!!!!!!!!!!!!!!!

Anonymous said...

Very Good. Thank you!

Anonymous said...

Perfect! Huge time saver, thank you!

Anonymous said...

Thank you

Anonymous said...

Tried this in access with now value and it worked, then replaced with my own date field value and I got errors where I had null dates. I will probably figure out how to solve the null dates bit but thought i'd let you know.

Anonymous said...

To handle null values in Access use Nz(Date, "ValueToUse")

Unknown said...

Can this be modified for the previous month?

Anonymous said...

Very Good. Saved me a lot of time. Thank you very much - Binu

Anonymous said...

AWSOME!! Thanks!