Date Range. Without year ...

Date Range. Without year ...

Post by shappe » Tue, 09 Sep 2008 15:26:55


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
 
 
 

Date Range. Without year ...

Post by Peter Morr » Tue, 09 Sep 2008 16:19:52

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 :-)

 
 
 

Date Range. Without year ...

Post by Ben Voigt » Wed, 10 Sep 2008 01:38:19


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).