Date 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
 
P

Peter Morris

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

Ben Voigt [C++ MVP]

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

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

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

Similar Threads


Top