2

I have bound date fields(datetime type column values) to my Grid. In the grid, the column definition is like so My code is:

<asp:Label id="lblFromTimeForTeacher" runat="server" Text='<%# Eval("FromTime", "{0:hh/mm}")%>' Visible="false" Width="99%" />

Right now, the label text is 08-45. Could someone please tell how can I get the label text as 08:45? Thanks in advance.

2 Answers 2

3

Custom DateTime formatting here. In your case just change to Convert.ToDateTime(Eval("FromTime")).ToString("hh:mm")

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

Comments

1

Try the following

<asp:Label ID="lblFromTimeForTeacher" runat="server" Text='<%# Eval("FromTime", "{0:hh:mm}")%>' Visible="false" Width="99%" />

if you want in "4:05 PM" format then try the following

<asp:Label ID="lblFromTimeForTeacher" runat="server" Text='<%# Eval("FromTime", "{0:t}")%>' Visible="false" Width="99%" />

For more you can review This Link hope this will help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.