Home > DeveloperSection > Forums > How to get Datetimepicker with seconds in asp.net?
Pravesh Singh

Total Post:411

Posted on    January-07-2015 10:21 PM


 1 Reply(s)
 724  View(s)
Rate this:

i have a task that i have to filter the records based on DateFrom and DateTo. in mysql the date fromat is in '2014-07-18 20:03:08' like this. In front end i used DatetimePicker to textbox..datetimepicker format results gives '2014/07/09 14:00'. so not possible for compare db dateformat and datetime formate.

i want datetime picker with seconds..plz help me

Royce Roy
Royce Roy

Total Post:134

Posted on    January-08-2015 2:49 AM

A DateTimePicker stores a DateTime in the Value property. You can add desired seconds to it:

DateFrom.Value = DateFrom.Value.AddSeconds(seconds);

datetimepicker format results gives '2014/07/09 14:00'.

Don't use strings as parameters for datetime-columns in MySql. Instead use sql-parameters and pass the DateTime directly:

// add seconds if you want, but i don't see any reason for it

// maybe you want to include the To-date, then you can add a day - one second

DateTo.Value = DateTo.Value.AddDays(1).AddSeconds(-1);


using (MySqlConnection conn = new MySqlConnection("connStr"))






        string sql = @"SELECT t.From, t.To, OtherColumns...

                       FROM TableName t

                       WHERE FROM >= @From AND To <= @To";

        using(MySqlCommand cmd = new MySqlCommand(sql, conn))


            cmd.Parameters.AddWithValue("@From", DateFrom.Value);

            cmd.Parameters.AddWithValue("@To", DateTo.Value);

            using (MySqlDataReader reader = cmd.ExecuteReader())


                while (reader.Read())


                    // ...





    } catch (Exception ex)






Don't want to miss updates? Please click the below button!

Follow MindStick