0

I am currently working with a gridview and would like to convert my total minutes field into hh:mm

This is what my code looks like now, it is taking the total minutes and giving back hh.00

 </asp:TemplateField>
                <asp:TemplateField HeaderText="Hours" HeaderStyle-Width="88px">
                    <ItemTemplate>                       
                        <%# (((PendingApprovalListData)Container.DataItem).TotalMinutes / 60.00).ToString("N2")%>
                    </ItemTemplate>
HELP_ME
  • 2,619
  • 3
  • 24
  • 31
  • What you are doing would really benefit from a `TimeSpan` object. What are you data binding to? Is it a DataTable/DataSet, or a list of entity objects? I'm thinking of working towards something like the accepted answer to this question: http://stackoverflow.com/questions/463642/c-what-is-the-best-way-to-convert-seconds-into-hourminutessecondsmilliseco – Katie Kilian Jun 26 '12 at 13:55

2 Answers2

1
you can use this code :

    var Hours = Math.floor(Yourvariable/60);
    var Minutes = Yourvariable%60;

Or you can use this

var span = System.TimeSpan.FromMinutes(Yourvariable);
var hours = ((int)span.TotalHours).ToString();     
var minutes = span.Minutes.ToString();
Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
0

Example for client side

<ItemTemplate>
    <asp:Label ID="lblExemptionDate" runat="server" Text='<%#Bind("ExemptDate","{0:dd MMM yyyy HH:mm:ss}")%>'></asp:Label>
</ItemTemplate>
Satinder singh
  • 10,100
  • 16
  • 60
  • 102