How can I understand 5 days past date.
Like: today-5=five days past date from today.
Thanks for help.
Printable View
How can I understand 5 days past date.
Like: today-5=five days past date from today.
Thanks for help.
You can use the datediff function
something like datediff(date1,date2)
You can also use the DateAdd function... The function has the following syntax:
DateAdd(Interval, Number, Date)
For example, if you want a date that lies 5 days earlier than today, then use this code:
The Interval argument can be "s" for seconds, "n" for minutes, "h" for hours, "d" for days, "w" for weeks, "m" for months, "y" for years, and there are others....Code:Dim FiveDaysAgo As Date
FiveDaysAgo = DateAdd("d", -5, Now()) ' get today and subtract 5 days
Debug.Print "Today is " & Now()
Debug.Print "5 days ago was " & FiveDaysAgo
Anyway, the Number argument can be negative, zero, or positive. Specifying a negative number subtracts time indicated by number and interval, e.g. -5 and "n" to subtract five minutes. Specifying a positive number will add the time specified by the interval and number.
The Date argument is simply the date to add/subtract to/from.
Hope this helps.
Thanks. It is working.