Hi, I got a question to check if a date time is within another date range (So as to check conflicting schedule)
There are various possible types of schedule:
1: One time start - end event. Typically such schedules is like a tour / outing / camp event, and hence I compare it using VB code as
If CurrentStartDate >= checkstartDate And CurrentEndDate <= checkendDate Then
'Do whatever
'CurrentStartDate is the selected start date time of the time slot while cuurentEndDate is the selected ending date time of the time slot.
'checkstartdate and checkenddate is the previously selected starting / ending date time (As I select the schedules by listbox with multiple selection mode)
End If
2: Weekly / Monthly event. This type of schedule could have been a regular event such as a course or a regular volunteer work (Like every sunday do some community service for the year 2011)
For this, it is certainly not going to be throughout for the peroid of time and hence the 1st example cannot work.
2a: More complicated bi-weekly / bi-monthly event. Similar concept to Point 2, but it is just a bi-weekly / monthly event.
For this, I have used a code like
Dim GetWeekNoOfMonth As Integer
GetWeekNoOfMonth = GetWeekOfMonth(CDate(CurrentStartDate))
MsgBox(GetWeekNoOfMonth)
with the fuction of
Public Shared Function GetWeekOfMonth(ByVal [date] As DateTime) As Integer
Dim beginningOfMonth As New DateTime([date].Year, [date].Month, 1)
While [date].[Date].AddDays(1).DayOfWeek <> CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek
[date] = [date].AddDays(1)
End While
Return CInt(Math.Truncate(CDbl([date].Subtract(beginningOfMonth).TotalDays) / 7.0F)) + 1
End Function
in order to get the start of the event's date is in which week of the month, and if the week number falls into an odd number, then every odd number weeks will means the event will take place. However, this code will only work on the current month of startdate. (Meaning, if I plan to schedule a bi-weekly saturday community service on 2010 June 2 to 2010 November 24 will not work since 2010 June has 5 weeks where the first community service in july should be on the 2nd week instead.
3: The even more complicated ones, Exclusion dates. After the first 2 has done, I have my final question on this topic, which is like for an example, on 2010 November 17 is a public holiday in my region, and therefore I will excuse myself from the community service. (Note: The exclusion will be specified in an exact date, so there is no need to check for holidays by user's country. The reason given here is mere example only so as to see the point of this function)
Thanks a lot for answering this question, which seemed to be a complicated task.