Formatting SQL Time column

  • Thread starter Thread starter David C
  • Start date Start date
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>
 
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,


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top