Asked by:
remove last :00 from label intime

Question
-
User-807418713 posted
Hello
This is my code
<asp:TemplateField HeaderText="In Time"> <ItemTemplate> <asp:Label ID="L3" runat="server" Width="90px" Text='<%# Eval("In_Time") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList id="EL3" tabIndex=18 runat="server" Font-Bold="True" Font-Names="Palatino Linotype" ForeColor="Black" Width="90px" AppendDataBoundItems="True" CssClass="chzn-select" AutoPostBack="True" OnSelectedIndexChanged="EL3_SelectedIndexChanged" > </asp:DropDownList> <asp:Label ID="EL3EL3" runat="server" Width="90px" Text='<%# Eval("In_Time") %>'></asp:Label> </EditItemTemplate> </asp:TemplateField>
It shows label data like this 11:00:00
but i want to show only like this 11:00
how to remove last :00 in label
Thanking You
Sunday, May 30, 2021 4:07 PM
All replies
-
User-943250815 posted
Try
<%# String.Format("0:HH:mm, Eval("In_Time")) %>
Take a look at
https://www.mikesdotnetting.com/article/23/date-formatting-in-c
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-stringsSunday, May 30, 2021 4:21 PM -
User-807418713 posted
Hi Jzero
In sql table my Intime column in time7 datatype
It showing in sql as like this data for example
In_Time
09:00:00.0000000
18:00:00.0000000I want to show in my label as only
09:00
18:00I tried this code below not working
<asp:Label ID="EL3EL3" runat="server" Width="90px" Text='<%# Eval("In_Time", "{0:HH:mm}") %>'></asp:Label>
check please
Thanking you
Sunday, May 30, 2021 4:37 PM -
User-943250815 posted
Review your Eval as in my previous message, it is not correct. If data is in DateTime or Time format it should work.
If does not work check last message in this thread https://forums.asp.net/t/1583274.aspx?GridView+time+7+convert+to+time+5+ (similar issue)Sunday, May 30, 2021 10:20 PM -
User409696431 posted
Use the code you were shown by jzero. Your code is incorrect.
Monday, May 31, 2021 12:16 AM -
User-807418713 posted
Hello
This is my code
<asp:TemplateField HeaderText="In Time"> <ItemTemplate> <asp:Label ID="L3" runat="server" Width="90px" Text='<%# Eval("In_Time") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:DropDownList id="EL3" tabIndex=18 runat="server" Font-Bold="True" Font-Names="Palatino Linotype" ForeColor="Black" Width="90px" AppendDataBoundItems="True" CssClass="chzn-select" AutoPostBack="True" OnSelectedIndexChanged="EL3_SelectedIndexChanged" > </asp:DropDownList> <asp:Label ID="EL3EL3" HtmlEncode="false" runat="server" Width="90px" Text='<%# Eval("In_Time", "{0:HH:mm}") %>'></asp:Label> </EditItemTemplate> </asp:TemplateField>
Please tell me where im wrong and correct my code it would be needful
Thanking You
Monday, May 31, 2021 6:50 AM -
User409696431 posted
Look at your code. Look at jzero's code. It's a simple comparison. What you have between
<%# and %>
is wrong.
Monday, May 31, 2021 11:58 AM -
User-807418713 posted
please check this error
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1010: Newline in constant
Source Error:Line 455: </asp:DropDownList> Line 456: Line 457: <asp:Label ID="EL4EL4" runat="server" Width="90px" Text='<%# String.Format("0:HH:mm, Eval("In_Time")) %>'></asp:Label> Line 458: </EditItemTemplate> Line 459: </asp:TemplateField>
Monday, May 31, 2021 5:32 PM -
User-943250815 posted
Oops, sorry I mistyped, please try again with
<%# String.Format("{0:HH:mm}", Eval("In_Time")) %>
Monday, May 31, 2021 6:07 PM -
User-1716253493 posted
Try Cast/convert the time to datetime in select command, then use the format
Select cast(in_time as datetime) as in_time, ...
Text='<%# Eval("In_Time","{0:HH:mm}" %>'
Monday, June 7, 2021 3:50 PM