Rynoc
Rynoc

Reputation: 45

Determine if date is before or after the 15th of the month

I have a function which applies a rate based on the number of months that an item has been stored. However we charge half that rate if the item was stored after the 15th. The function I'm using to determine the amount of months an item is stored is the DateDiff() Function. It returns the number of months between two dates. How do I determine if the date is before the 15th or after? If I use DateDiff(d,1/1/2015, 4/1/15) I would get a value greater than 15 so I cannot see if the Date is before or after the 15th using greater than or less than 15. How can I determine if either of the dates (entrance date which is the date the item entered into the storage area and the exit date which is the date it is removed) are before or after the 15th?

Upvotes: 1

Views: 2488

Answers (2)

Bathsheba
Bathsheba

Reputation: 234875

VBA models a date as an floating point double. The integral part stands for the day. It advances by 1 per day.

It provides a function Day(date) which you can use to extract the day of the month in which date occurs.

For example, CDate(40000) will return you 6-July-2009, and Day(40000) returns you 6.

Upvotes: 1

Sam
Sam

Reputation: 948

I would do something like

if format(date, "DD") <= 15 then msgbox "this is 15 or below" else msgbox "this is 16 and above" end if

You can put a date variable in instead of date which is a built in function to return the system date.

Upvotes: 0

Related Questions