hi,

1-how can i do multiselect in calendar.
2-how many days between 2 dates? how can u calculate it?
example :
10/10/2006 - 12/10/2006 there is 1 day between those 2 dates.

thanks

Dani AI

Generated

As asked about multi-select and counting days, and pointed to the Calendar's built‑in selection and a DateDiff-based approach, here are a few clarifications and safer ways to get the result you actually want (avoid the usual off‑by‑one and time‑of‑day traps).

"Days between" can mean different things: inclusive (how many calendar days the range touches) or exclusive (how many full days lie strictly between the two dates). For your example, 10/10/2006 → 12/10/2006 is 3 days inclusive and 1 day exclusive. Always normalize to date-only values (discard the time component) before subtracting so partial days or time zones don't skew results.

A robust server-side approach is to work with DateTime and TimeSpan instead of string math. Example (C# and VB) that ignores time-of-day and gives both inclusive and exclusive counts:

var start = new DateTime(2006, 10, 10);
var end = new DateTime(2006, 10, 12);
int days = (end.Date - start.Date).Days;
int inclusive = days + 1;
int exclusive = Math.Max(0, days - 1);
Dim startDate As New DateTime(2006, 10, 10)
Dim endDate As New DateTime(2006, 10, 12)
Dim days As Integer = (endDate.Date - startDate.Date).Days
Dim inclusive As Integer = days + 1
Dim exclusive As Integer = Math.Max(0, days - 1)

If you use the ASP.NET Calendar control (as suggested), read the control's selected‑dates collection in the SelectionChanged handler and decide whether you need the number of selected items (non‑contiguous picks) or the span between earliest and latest selection. When working client-side in JavaScript, compute UTC dates (use Date.UTC) to avoid DST issues. For reference, see the ASP.NET Calendar docs and the DateTime/Date.UTC guidance: ASP.NET Calendar control documentation and Date.UTC (MDN). Also validate/parset input with culture-aware parsing (TryParseExact) to avoid dd/mm vs mm/dd confusion.

Recommended Answers

All 2 Replies

1-how can i do multiselect in calendar.
thanks

Select Calendar control and set SelectionMode property to DayWeek or DayWeekMonth.

2-how many days between 2 dates? how can u calculate it?
example :
10/10/2006 - 12/10/2006 there is 1 day between those 2 dates.
thanks

You can use DateDiff function Here is the sample:

DateDiff(DateInterval.Day, MyFirstDate, MyLastDate)[B]-1[/B]

If you need to count days in Caledar control than simply add this in SelectionChanged event od the Calendar control:

Me.Calendar1.SelectedDates.Count

Hope it helps.

Hi ManicCW,

Thank you very much for your help. they work very well.

Kind regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.