---
title: "How to get Datetimepicker with seconds in asp.net?"  
description: "How to get Datetimepicker with seconds in asp.net?"  
author: "Pravesh Singh"  
published: 2015-01-07  
updated: 2015-01-08  
canonical: https://www.mindstick.com/forum/12848/how-to-get-datetimepicker-with-seconds-in-asp-dot-net  
category: "c#"  
tags: ["asp.net", "mysql"]  
reading_time: 2 minutes  

---

# How to get Datetimepicker with seconds in asp.net?

I have a [task](https://www.mindstick.com/forum/161761/what-is-the-difference-between-task-and-thread) that i have to [filter](https://www.mindstick.com/forum/1176/filter-in-a-xml-file-in-c-sharp) the [records](https://www.mindstick.com/forum/34640/how-to-create-a-stored-procedure-for-display-all-records) based on DateFrom and DateTo. in [mysql](https://www.mindstick.com/articles/12156/what-is-mysql) the [date](https://yourviews.mindstick.com/story/3869/propose-day-2024-exciting-date-ideas-for-you-and-your-partner) fromat is in '2014-07-18 20:03:08' like this. In [front end](https://www.mindstick.com/forum/12668/send-date-from-my-front-end-angular-to-c-sharp-dot-net-datetime-webapi) i used DatetimePicker to textbox..datetimepicker [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format) [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) gives '2014/07/09 14:00'. so not possible for [compare](https://www.mindstick.com/forum/2036/propertyinfo-getvalue-unable-to-compare-datetimes) db dateformat and [datetime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty) formate.

i want datetime picker with seconds..plz help me

## Replies

### Reply by Royce Roy

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 secondDateTo.Value = DateTo.Value.AddDays(1).AddSeconds(-1); using (MySqlConnection conn = new MySqlConnection("connStr")){    try    {        conn.Open();         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)    {        Console.WriteLine(ex.ToString());    }}
```


---

Original Source: https://www.mindstick.com/forum/12848/how-to-get-datetimepicker-with-seconds-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
