2013-04-29 4 views
-2

체크인 날짜와 체크 아웃 일자의 차이를 찾는 방법.날짜와 시간의 차이 확인 JavaScript

function Checkdate(id) 
{ 
    var txtCheckinNew = $(id).parents("table").find("#[id$=TransferDate]").val(); //04/30/2013 
    var txtCheckoutNew =$(id).parents("table").find("#[id$=TransferDate1]").val(); //05/03/2013 
    var diff = Date(txtCheckoutNew) - Date(txtCheckinNew); 
    alert(diff);  
} 
+2

입력 데이터가 어떤 형식 에 봐주십시오 사용할 수 있습니까? 출력은 무엇이되어야합니까? – banzsh

+0

체크인 : - 04/30/2013 체크 아웃 : - 05/03/2013 –

+0

var diff = new 날짜 (txtCheckoutNew) - 새 날짜 (txtCheckinNew); – Jashwant

답변

1

당신은 Date.parse

var txtCheckinNew = Date.parse($('#TransferDate').val()); 
var txtCheckoutNew = Date.parse($('#TransferDate1').val()); 
alert((txtCheckoutNew-txtCheckinNew)/(24*60*60*1000)); 

JS Fiddle

1

http://jsfiddle.net/2dJAN/1/

<div class="date"></div> 

var Date1 = new Date (2008, 7, 25); 
var Date2 = new Date (2008, 7, 27); 
var one_day = 1000*60*60*24; 
var Days = (Date2.getTime() - Date1.getTime())/(one_day) 
$('.date').html(Days)