Formatting SQL Time column

D

David C

We have an SQL 2008 server database with a Time(0) data type. I am trying
to format the Label in a GridView to show the time as h:mm AM ( for example
9:00 AM). I have the format below in the Bind that is giving me 9:00:00.
Can someone help me with this format? Thanks.

David

<asp:Label ID="LblToDoTime" runat="server" Text='<%# Bind("ToDoTime",
"{0:h:mm tt}") %>'></asp:Label>
 
G

Gregory A. Beamer

We have an SQL 2008 server database with a Time(0) data type. I am
trying to format the Label in a GridView to show the time as h:mm AM (
for example 9:00 AM). I have the format below in the Bind that is
giving me 9:00:00. Can someone help me with this format? Thanks.

David

<asp:Label ID="LblToDoTime" runat="server" Text='<%# Bind("ToDoTime",
"{0:h:mm tt}") %>'></asp:Label>


I don't know the "simple binding" answer to this. It is possible that
the new Time only data type does not use the format, as it is a new type
and not compensated for in ASP.NET. If this were a DateTime, your code
would likely be working, but with a completely new way of storing Date
and Time separately, bets are off.

This does not mean you are completely out of luck, as you use the row
databinding events and manually bind the time for each row using your
own formatting code. It is a bit more work, but it will work.

I wish I had a better answer, but I have yet to work with the Time
column in any of my assignments (professional or fun).

Peace and Grace,
 
D

David C

Mark Rae said:
<asp:Label ID="LblToDoTime" runat="server" HtmlEncode="false"
Text='<%# Bind("ToDoTime", "{0:h:mm tt}") %>' />
That did it. Thanks.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top