CSharp/C# >> Date Range. Without year ...

by shapper » Mon, 08 Sep 2008 14:26:55 GMT

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

CSharp/C# >> Date Range. Without year ...

by Peter Morris » Mon, 08 Sep 2008 15:19:52 GMT


Create new dates based on the month, day and use those. I would recommend
using a leap year, just in case the source was a leap year too :-)

CSharp/C# >> Date Range. Without year ...

by Ben Voigt [C++ MVP] » Tue, 09 Sep 2008 00:38:19 GMT


Or subtract out the year, i.e.

otherDate - new DateTime(otherDate.Year, 1, 1)

or DateAdd(otherDate, 'y', -otherDate.Year) -- not sure what the new
function is for this

This keeps all the time information and so forth without having to code for
each non-year field. Note however that if you want to check the day of the
week, you'd better use the original date with the year (subtraction creates
a TimeSpan, not a DateTime with the year erased).

Similar Threads

1. a Calendar with date range selection, year navigation

2. Date Ranges on relative "dates"

3. FInding the days between 2 dates without using the inbuilt date functions or the DateTime Type

I have an assignment that I have to complete. I have to write a
windows app in C#. Here is the spec:

1/ Date Comparison
Build a program that will find the number of days between two dates.
You CANNOT use the inbuilt date functions or the DateTime Type.   Your
program should work with any date between 1900 and 3000.
 
Here are your acceptance tests:
 
Days between 04/01/02 and 01/01/02 equals 3
Days between 01/05/1998 and 12/10/1977 equals 7506
Days between 01/01/2004 and 01/01/2003 equals 365
Days between 01/01/2002 and 01/01/2000 equals 731

I figure I could convert the dates to doubles and then subtract one
from the other but that wouldnt take leap years into account!!

Any ideas to get me started would be really appreciated!!

thanks
RuSs

4. Only allow a Year Range in textbox control - Microsoft .NET Framework

5. current date minus 2 year

Hi,

How can I calculate the date 2 years ago?

I get a problem with datetime minus int (year).

Can someone help?

Thanks! 


6. Years, Months and Days between tow dates - CSharp/C#

7. Difference in years between 2 Julian dates..

Hello!

Can someone show me an example for getting the difference in years
between 2 julian dates please...or perhaps you could point me to some
useful information please.

8. Difference in years of 2 dates (COleDateTime)