C# .NET - how to check date count in mysql - Asked By abinav shankar on 31-Jan-12 06:15 AM


I want to check whether a person has applied for leave today for that i am passing datetime.now as parameter but i am getting null as result but there records already exists in the table how to check it

smr replied to abinav shankar on 31-Jan-12 06:16 AM

try this

DateTime minDate = DateTime.MaxValue;
DateTime maxDate = DateTime.MinValue;
foreach (string dateString in StringDates)
  DateTime date = DateTime.Parse(dateString);
  if (date < minDate)
    minDate = date;
  if (date > maxDate)
    maxDate = date;
Jitendra Faye replied to abinav shankar on 31-Jan-12 06:18 AM
First convert both date  (Front end and back end ) to dateFormat, because comparision can be done only between same format.

Try and let me know.
Venkat K replied to abinav shankar on 31-Jan-12 06:20 AM
How you are checking the date? In which format you are storing date in my sql db?

Have you tried in this format?

or you can use the DATE_FORMAT to convert the date value to the required value, with the option specified in the below link:



dipa ahuja replied to abinav shankar on 31-Jan-12 06:23 AM
Check the dataTime column with this query:

string q= "Select Count(*) from table1 where ename='" + TextBox1.Text + "' AND leaveDate='" + DateTime.Now.ToShortDateString() +"'" ;

Now bind it with dataAdapter and DAtaTable and check the rows count if its > 0 means this person have taken the leave