|
-
Jan 23rd, 2002, 05:12 AM
#1
Subtract months from Date data type
I am using the Date data type and am using the following code:
'Calculate delete date
Select Case RetainUnit
Case "Days"
dtmDeleteDate = Now() - RetainNumber
Case "Weeks"
dtmDeleteDate = Now() - (RetainNumber * 7)
Case "Months"
'dtmDeleteDate = Now() - ??????
End Select
The only thing is that the Date data type only seems to lend itself to maths involving whole days (integers) or hours (fractions - ie 1/24 = 1 hour).
My question is, how can I subtract 1 month. And I don't want to subtract 30 days or whatever. So if I've got 21/05/02, then subtracting 1 month would give 21/04/02. And it works regardless of days in the month (28/29/30/31).
Is there another data type that I should be using; or a function that I've yet to discover??
Thanks in anticipation.
-
Jan 23rd, 2002, 05:15 AM
#2
Bouncy Member
use the DateAdd function
look it up in MSDN library
i.e.
myDate = DateAdd(-1,"m",myDate)
would subtract 1 month from myDate
Good Luck
-
Jan 23rd, 2002, 05:39 AM
#3
Thanks.
I actually found DateAdd in MSDN about a minute after I'd posted the thread!! -oops!
Mind you MSDN is such a pain to navigate at times, that it could have taken me ages to get anywhere!
-
Jan 23rd, 2002, 06:25 AM
#4
Bouncy Member
yeah, and if you ever use the Search facility you nearly always get the maximum 500 matching search results to skim through
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|