How to calculate difference between two dates in textboxes in C#.

  • Thread starter Thread starter Deepa Loganathan
  • Start date Start date
D

Deepa Loganathan

Guest
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:


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);
}

<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">

<asp:requiredfieldvalidator id="RequiredFieldValidator6" runat="server" forecolor="Red" controltovalidate="tp_ActEndtime" validationgroup="ReceiptSave" errormessage="*" font-bold="true">

<asp:label id="Label2" runat="server" text="Act Value:">

<%--<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">

<asp:label id="Label3" runat="server" text="Efficiency (in %):">


Continue reading...
 
Back
Top