---
title: "How to add date in dd/MM/yyyy to mysql in asp.net?"  
description: "How to add date in dd/MM/yyyy to mysql in asp.net?"  
author: "Anonymous User"  
published: 2014-12-11  
updated: 2014-12-11  
canonical: https://www.mindstick.com/forum/12780/how-to-add-date-in-dd-mm-yyyy-to-mysql-in-asp-dot-net  
category: "asp.net"  
tags: ["mysql", "sql server"]  
reading_time: 1 minute  

---

# How to add date in dd/MM/yyyy to mysql in asp.net?

I've used an [ajax](https://www.mindstick.com/articles/1541/check-availability-of-user-name-or-email-using-asp-dot-net-ajax-and-jquery) [calendarExtender](https://www.mindstick.com/forum/145/calendarextender-is-hiding-behind-modalpopup) [tool](https://www.mindstick.com/articles/12857/customization-software-a-perfect-tool-for-e-store-owners-to-make-big-bucks) and set [Format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format) to dd/MM/yyyy while inserting the [date](https://yourviews.mindstick.com/story/3869/propose-day-2024-exciting-date-ideas-for-you-and-your-partner) 21/12/2013 to [mysql](https://www.mindstick.com/articles/12156/what-is-mysql) its [giving](https://yourviews.mindstick.com/view/80639/regifting-is-far-better-than-giving-away-a-bouquet) [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing)

```
MySqlConnection conn = new MySqlConnection(cnnstring); string cmdText = "INSERT INTO trydate(Dob) VALUES ('" + TextBox1.Text + "')"; MySqlCommand cmd = new MySqlCommand(cmdText, conn);conn.Open();int a = cmd.ExecuteNonQuery();Label1.Text = "Data Saved";TextBox1.Text = "";
```

please help me to [overcome](https://www.mindstick.com/articles/12983/remedies-to-overcome-the-hdmi-connection-problems) from this.

## Replies

### Reply by Lillian Martin

Use DateTime.ParseExact Method to convert TextBox1.Text to a DateTime variable, and change your query to parameterized query to avoid SQL injection. Also, use using statement to make sure that conn is closed after executing cmd.ExecuteNonQuery()

```
DateTime dob = DateTime.ParseExact(TextBox1.Text, "dd/MM/yyyy", null); using (MySqlConnection conn = new MySqlConnection(cnnstring)){    string cmdText = "INSERT INTO trydate(Dob) VALUES (@Dob)";     using (MySqlCommand cmd = new MySqlCommand(cmdText, conn))    {        cmd.Parameters.AddWithValue("@Dob", dob);        conn.Open();        int a = cmd.ExecuteNonQuery();        Label1.Text = "Data Saved";        TextBox1.Text = "";    }}
```

### Reply by Anurag Sharma

Try this,

```
string strText=TextBox1.Textstring qryStr = string.Format("{0:yyyy/MM/dd
HH:mm:ss}", Convert.ToDateTime(strText));string cmdText = "INSERT INTO trydate(Dob) VALUES
('" + qryStr + "')";
```


---

Original Source: https://www.mindstick.com/forum/12780/how-to-add-date-in-dd-mm-yyyy-to-mysql-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
