By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,559 Members | 1,150 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,559 IT Pros & Developers. It's quick & easy.

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

P: n/a

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
Nov 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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" <id*************************@reallyidont.com> wrote in
message news:c7*******************@news.demon.co.uk...

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

Nov 20 '05 #2

P: n/a
Ahh, thats great, thx.

"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
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" <id*************************@reallyidont.com> wrote in
message news:c7*******************@news.demon.co.uk...

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


Nov 20 '05 #3

P: n/a
"Robin Tucker" <id*************************@reallyidont.com> schrieb

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

Nov 20 '05 #4

P: n/a
CJ Taylor wrote:
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:c7*******************@news.demon.co.uk...
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?


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.

--
Sven Groot

http://unforgiven.bloghorn.com

Nov 20 '05 #5

P: n/a
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)....

"Sven Groot" <sv*******@gmx.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
CJ Taylor wrote:
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:c7*******************@news.demon.co.uk...
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?


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.

--
Sven Groot

http://unforgiven.bloghorn.com

Nov 20 '05 #6

P: n/a
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 ;)

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"Robin Tucker" <id*************************@reallyidont.com> schrieb

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

Nov 20 '05 #7

P: n/a
I'm pretty sure AddMonths takes care of that for you..
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:c7*******************@news.demon.co.uk...
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)....

"Sven Groot" <sv*******@gmx.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
CJ Taylor wrote:
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:c7*******************@news.demon.co.uk...
> 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?

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.

--
Sven Groot

http://unforgiven.bloghorn.com


Nov 20 '05 #8

P: n/a
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

Nov 20 '05 #9

P: n/a
damnit.... Duely noted. =)

Thanks Cor
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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


Nov 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.