DateTime Range. Without year ...

S

shapper

Hello,

I am checking a DateTime variable to check if in range: low <
MyDateTime < high.

However, I know need do the same but not care about the year. Can I do
this?

Thanks,
Miguel
 
S

shapper

Bring an example what you mean.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net


I am checking a DateTime variable to check if in range: low <
MyDateTime < high.
However, I know need do the same but not care about the year. Can I do
this?
Thanks,
Miguel

Well, consider the following two dates:

Start:
2007-09-08 11:29:50

Finish:
2007-10-12 12:30:20

Then the test date:
2008-09-22 08:29:50

The test date is between the other two dates if you don't consider the
year. That is what I need to test.

Thanks,
Miguel
 
E

Eliyahu Goldin

Then you simply need to bring all dates to the same year:

DateTime startToTest = new DateTime(test.Year, start.Month, start.Day);
DateTime finishToTest = new DateTime(test.Year, finish.Month, finish.Day);

and check if startToTest < test < finishToTest.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Bring an example what you mean.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net


I am checking a DateTime variable to check if in range: low <
MyDateTime < high.
However, I know need do the same but not care about the year. Can I do
this?
Thanks,
Miguel

Well, consider the following two dates:

Start:
2007-09-08 11:29:50

Finish:
2007-10-12 12:30:20

Then the test date:
2008-09-22 08:29:50

The test date is between the other two dates if you don't consider the
year. That is what I need to test.

Thanks,
Miguel
 
E

Eliyahu Goldin

Then you simply need to bring all dates to the same year:

DateTime startToTest = new DateTime(test.Year, start.Month, start.Day);
DateTime finishToTest = new DateTime(test.Year, finish.Month, finish.Day);

and check if startToTest < test < finishToTest.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Bring an example what you mean.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net


I am checking a DateTime variable to check if in range: low <
MyDateTime < high.
However, I know need do the same but not care about the year. Can I do
this?
Thanks,
Miguel

Well, consider the following two dates:

Start:
2007-09-08 11:29:50

Finish:
2007-10-12 12:30:20

Then the test date:
2008-09-22 08:29:50

The test date is between the other two dates if you don't consider the
year. That is what I need to test.

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top