473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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


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
9 1849
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
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
"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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: [H]omer | last post by:
What is the property that defines the difference between the line-hight and the font-size? E.g.: I have two <div>'s with no properties set at all. I then give the second div a left margin...
16
by: DFS | last post by:
If you're listening, I want the middle of the calendar (showing 1 month) to open below the cursor position. It currently opens just to the right and below the cursor position. I hunted through...
2
by: ezelasky | last post by:
Very new to dot net & more familiar with COM+, can someone send me a link on how to create a single file assembly as a dll? Do I do this in ..NET visual IDE or from the command line? How does one...
1
by: Kylin | last post by:
something has wrong when I create a shopping cart in asp.net , and any Document about the shopping cart ?
8
by: sherifffruitfly | last post by:
Hi all, The following function is the ValueChanged handler for two DateTimePicker thingies - allowing the user to specify a date range. I don't understand why the following bug exists: when the...
12
by: Alan Isaac | last post by:
Are relative imports broken in 2.5? Directory ``temp`` contains:: __init__.py test1.py test2.py File contents: __init__.py and test2.py are empty test1.py contains a single line::
7
by: hempknight | last post by:
Hi! all this is probably been answered in part elsewhere but does anyone know how to get Dates that are 30 days from the current date on the system? my Database has a field to hold the Warranty...
2
by: elastreto | last post by:
Hello, I am running a query on all employees hired between 9 and 12 months ago. To do this, I have defined the following static criteria: Between #9/28/2006# And #12/28/2006# And Is Not...
3
by: Keith Hughitt | last post by:
Hi all, I was wondering if someone could help me out with a question about PHP Dates. I would like to pass a date to PHP via a query string, using ISO 8601 formatting ("2008-09-15T00:00:00Z"). I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.