Converting DateTime to just Date not working

I’m trying to convert my DateTime to just Date “dd-MM-yyyy”. I cannot get it to work. It seems I’m missing something simple here. I’ve tried so many different ways of doing this, listed below. I’m now out of ideas.

On my aspx.cs page

lblduedate.Text = dt.Rows[0]["DueDate"].ToString("dd-MM-yyyy");

On my aspx page

<asp:Label ID="lblduedate" runat="server" ></asp:Label>

I’ve also on the aspx page, tried different formats of

Text='<%# Eval("DueDate", "{0:dd/MM/yyyy}") %>'

What comes out?

And what is the type of whatever is in your datatable?

Output is 3/10/2004 12:00:00 AM

Data type is set to smalldatetime in the database.

So I’m not sure how it’s getting the longdatetime format.

It is a DateTime object, which can be output as any date format. You might have to cast it into a DateTime to use the ToString overloads like you are trying to use.

Yes, wwb is correct. The .ToString(format) you using is not doing anything. You first need to convert it to DateTime, then call you .ToString(format) on the DateTime object

eg. lblduedate.Text = ((DateTime)dt.Rows[0][“DueDate”]).ToString(“dd-MM-yyyy”);