Click here to Skip to main content
15,507,755 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thanks in advance.....while run the below code this error occurs
Min (2) must be less than or equal to max (-1) in a Range object.
For other dates it works good....only for this date it shows a error.

From Date = 04 Oct 2020
To date = 05 Oct 2020

What I have tried:

string FromDate = Convert.ToDateTime(e.Day.Date.ToShortDateString()).ToString("dd MMM yyyy");
                string ToDate = Convert.ToDateTime(e.Day.Date.AddDays(1).ToShortDateString()).ToString("dd MMM yyyy");
                DataRow[] rows = DTEvents.Select(
                 String.Format(
                    "FollowDate >= #{0}# AND FollowDate < #{1}#",
                FromDate, ToDate  // DateTime.Parse(e.Day.Date.ToShortDateString(), new System.Globalization.CultureInfo("pt-BR")).ToString("dd MMM yyyy"),
                                  // DateTime.Parse(e.Day.Date.AddDays(1).ToShortDateString(), new System.Globalization.CultureInfo("pt-BR")).ToString("dd MMM yyyy")
                 )
              );
Posted
Updated 3-Mar-21 22:53pm
Comments
20212a 3-Mar-21 9:26am    
Which line of code causes the error?
Member 15028582 3-Mar-21 22:41pm    
DataRow[] rows = DTEvents.Select(
String.Format(
"FollowDate >= #{0}# AND FollowDate < #{1}#",
FromDate, ToDate // DateTime.Parse(e.Day.Date.ToShortDateString(), new System.Globalization.CultureInfo("pt-BR")).ToString("dd MMM yyyy"),
// DateTime.Parse(e.Day.Date.AddDays(1).ToShortDateString(), new System.Globalization.CultureInfo("pt-BR")).ToString("dd MMM yyyy")
)
);
This line got error
Richard MacCutchan 3-Mar-21 9:56am    
Why do you convert Date types to strings in order to convert them back to DateTimes?

1 solution

Try this:
C#
DateTime FromDate = e.Day.Date;
DateTime ToDate = e.Day.Date.AddDays(1);
DataRow[] rows = DTEvents.Select($"FollowDate >= #{FromDate}# AND FollowDate < #{ToDate}#");


More at: DataTable.Select Method (System.Data) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900