Check if DateTime in specific range

Posted by katit on Stack Overflow See other posts from Stack Overflow or by katit
Published on 2011-11-22T01:19:21Z Indexed on 2011/11/22 1:50 UTC
Read the original article Hit count: 189

Filed under:
|
|
|

Need to check if DateTime is in specific range. I think I need to calculate knowing YEAR first and last date of DST time in this year.

How would I figure "Sunday of week 2 of March" date?

From 1/1/2007 12:00:00 AM to 12/31/9999 12:00:00 AM
  Begins at 2:00 AM on Sunday of week 2 of March
  Ends at 2:00 AM on Sunday of week 1 of November

For example, I need to check if 11/21/2011 is between Sunday of week 2 in March and Sunday of week 1 of November - answer should be NO

If I pass 8/8/2011 - answer should be yes.

Basically, I need to write function to check if my date belongs to daylight savings time. My only idea so far is to write loops to find 2nd week for example.

So, I would loop from Day 1 in March until I hit Sunday second time. Same thing I would loop (increment days by 1) from day 1 of November until I hit Sunday first time.

In another words, I need function to check if input data is in Daylight Savings time period. Time period defined by constraint above.

P.S. I can't use TimeZoneInfo since it's in Silverlight P.P.S I can't use DateTime.IsDaylightSavingsTime as I don't have times with kind "local"

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET