John M
John M

Reputation: 14668

ASP .NET C# - Format a MySQL date field properly in a listview

My MySQL database has a date field in the format:

yyyy-mm-dd

but in ASP .NET this shows as:

9/14/2009 12:00:00 AM

in both the ItemTemplate and EditItemTemplate.

How do I format the field to display properly?

Upvotes: 0

Views: 1600

Answers (2)

user3432665
user3432665

Reputation: 1

    DateTime dt = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
    qry = "select taxpercentage from tbl_tax where effectivedate contains '" + dt+ "'";
    con.returnscalar(qry); what is wrong in this

Upvotes: 0

Vadim
Vadim

Reputation: 21704

You can use ToShortDateString() method of DateTime. You also can use something like this:

DateTime dateTimeObject = Convert.ToDateTime("9/14/2009 12:00:00 AM");
dateTimeObject.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);

Upvotes: 3

Related Questions