Simple question about relative dates (ie. "last six months")

  • Thread starter Thread starter Robin Tucker
  • Start date Start date
R

Robin Tucker

Hiya,


I need to test "relative dates" in my program, such as "last six months" or
"last 3 months" or "in the last week" etc. How can I do this with a
DateTime structure?


ie. If NodeDate >= CurrentDate - six months (etc.)


Cheers
 
Hey Robin

Use the DateTime.AddMonths function

i.e.

dim nDate as DateTime
Dim cDate as datetime = Now()

nDate = cDate.AddMonths(-6) ' the - is for 6 months ago

-CJ
 
Robin Tucker said:
I need to test "relative dates" in my program, such as "last six
months" or "last 3 months" or "in the last week" etc. How can I do
this with a DateTime structure?


ie. If NodeDate >= CurrentDate - six months (etc.)

The problem is that one month is not a fixed period of time because it's
28 - 31 days, so how long do 6 month last? Subtracting one week is easier.
;-)


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Ahh, thats great, thx.

CJ Taylor said:
Hey Robin

Use the DateTime.AddMonths function

i.e.

dim nDate as DateTime
Dim cDate as datetime = Now()

nDate = cDate.AddMonths(-6) ' the - is for 6 months ago

-CJ
 
CJ said:
Use the DateTime.AddMonths function

i.e.

dim nDate as DateTime
Dim cDate as datetime = Now()

nDate = cDate.AddMonths(-6) ' the - is for 6 months ago

In addition to that, have a look at the TimeSpan structure, and the
DateTime.Add method that takes a TimeSpan as a parameter.
 
Yea, I saw that. I had a bit of a problem with "during this week" however,
as there is no concept of a "week" in any of the structures (apart from days
of the week of course).

Still can't work out how to formulate that (intelligence bypass)....
 
Well imho, in the last six months from, say, today, would take us back to
November 4th 2003. So I'm counting the month number rather than total
number of days which, as you say doesn't make sense to reason about ;)
 
Hi CJ,

I found it very nice, I do also not understand what the others want, and
typed by hand, by the way why are you using CDate without brackets surround
it.

:-)

Just to tickle you..

Cor
 
Back
Top