Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hai,

Any Body please help me..
am doing a project in ASP.NET
am having 2 texboxes and 1 label,

textbox1=get time in database(starting time ex:12:00)
textbox2=Ending time ex:13:00

i have to get difference in label ie,60(ie converted into minutes)

What I have tried:

ASP.NET
<script type="text/javascript">
function ActValuecheck() {
            var StartTime = $("#<%=lblstarttime.ClientID%>").text();
            var StartDate = $("#<%=hf_StartDate.ClientID%>").val();
            var EndTime = $("#<%=tp_ActEndtime.ClientID%>").val();
            var EndDate = $("#<%=dp_ReceiptDate.ClientID%>").val();
            var value = $("#<%=lblvalue.ClientID%>").text();

            var ST = StartTime.split(':');
            var ET = EndTime.split('-');
            var SD = StartDate.split('-');
            var ED = EndDate.split('-');
            var StartDate1 = new Date(SD[2], parseInt(SD[1]) - 1, SD[0], ST[0], ST[1], 0);
            var EndDate1 = new Date(ED[0], parseInt(ED[1]) - 1, ED[2], ET[3], ET[4], 0);
            //EndDate1.setHours(ET[3], ET[4], 0);
            var ActValue_InMin = (EndDate1 - StartDate1) / (60 * 1000);
            ActValue_InMin = parseFloat(ActValue_InMin).toFixed(0);
            document.getElementById("<%=lbl_Actvalue.ClientID%>").innerHTML = ActValue_InMin;
            document.getElementById("<%=lbl_Actvalue_hf.ClientID%>").value = ActValue_InMin;

            var Eff = (parseFloat(value) / ActValue_InMin) * 100;
            Eff = Eff.toFixed(2);
            $('#<%=lbl_Efficiency.ClientID%>').text(Eff);
            $('#<%=lbl_Efficiency_hf.ClientID%>').val(Eff);
        }
</script>

<div class="col-xs-3 col-sm-3 col-md-3">
                                    <div class="form-group">
                                        <asp:label id="Label7" runat="server" text="StartTime:" font-bold="True">
                                                            
                                        <asp:label id="lblstarttime" runat="server" text="" font-bold="True">
                                        <asp:hiddenfield id="hf_StartDate" runat="server">
                                    </div>
                                </div>
                                <div class="col-xs-1 col-sm-1 col-md-1">
                                    <div class="form-group">
                                        <asp:requiredfieldvalidator id="RequiredFieldValidator6" runat="server" forecolor="Red" controltovalidate="tp_ActEndtime" validationgroup="ReceiptSave" errormessage="*" font-bold="true">
                                    </div>
                                </div>
                            
                            <div class="row">

                                <div class="col-xs-5 col-sm-5 col-md-5">
                                    <div class="form-group">
                                        <asp:label id="Label2" runat="server" text="Act Value:">
                                    </div>
                                </div>
                                <div class="col-xs-6 col-sm-6 col-md-6">
                                    <div class="form-group">
                                        <%--<asp:textbox id="txtActvalue" enabled="false" runat="server" class="form-control input-md">--%>
                                        <asp:label id="lbl_Actvalue" runat="server" text="">
                                        <asp:hiddenfield id="lbl_Actvalue_hf" runat="server">
                                    </div>
                                </div>
                                <div class="col-xs-1 col-sm-1 col-md-1"></div>
                            </div>
                            <div class="row">
                                <div class="col-xs-5 col-sm-5 col-md-5">
                                    <div class="form-group">
                                        <asp:label id="Label3" runat="server" text="Efficiency (in %):">
                                    </div>
                                </div></div>
Posted
Updated 5-Jul-19 3:49am
v2
Comments
Richard MacCutchan 5-Jul-19 4:16am    
You need to learn about DateTime types and DateTime pickers.
MadMyche 5-Jul-19 9:49am    
I have edited your tags, your problem is more of a javascript/jquery question than C#/Asp.net; and I added in the proper markup for the code you have presented

1 solution

you should convert string to date then you could try this:

C#
DateTime date1 = Convert.ToDateTime(borrowed_date_txt);
      DateTime date2 = Convert.ToDateTime(return_date_txt);
      int result = DateTime.Compare(date1, date2);
      string relationship;

      if (result < 0)
         relationship = "is earlier than";
      else if (result == 0)
         relationship = "is the same time as";         
      else
         relationship = "is later than";
 
Share this answer
 
Comments
CHill60 5-Jul-19 3:42am    
Avoid using the Convert family of functions with user input. If the user gets the format wrong then your code will throw an exception. It is better practice to use DateTime.TryParse Method[^]
MadMyche 5-Jul-19 9:50am    
Please note that the calculation is being done in javascript, not C#

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900