0

I have a database which has date field and time field. I want to retrieve these two values from the DB and display them in a Label. I could do this by binding an SqlDataSource with the DB and using Eval in the label, but the problem is that I always get an extra 12:00:00 am when retrieving the date. For example if the date is 13/11/2015, when I retrieve it via asp.net I get, 13/11/2015 12:00:00 am.

I have executed a query in SQL itself and the results where correct with no 12:00:00 am. Also, when I configured the 'SqlDataSource' I clicked Test Query and the results were correct.

I couldn't figure out why I'm getting incorrect format when displaying it in a label. The label is placed inside a repeater ItemTemplate. All other retrived data from the DB are retrieved correctly from inside the repeater except date. Here is the code which places the date in the Label,

<span class="date_time_lbl">posted at: </span>
<asp:Label runat="server" Text='<%#Eval("tDate") %>'/>
<span> </span>
<asp:Label runat="server" Text='<%#Eval("Time") %>'/>

Can anyone please tell me what is causing this problem?

1 Answer 1

2

you can use formating in eval as a second parameter;

Eval("Date", "{0:d}")

for standard format options: https://msdn.microsoft.com/library/az4se3k1(v=vs.100).aspx

for custom options: https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, But I'm having the problem in the date field not the time field, did you mean Date?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.