http://jsfiddle.net/uWT4r/131/
I need the time in 12 hr format
If I enter
in first input field (start time) 12:00 AM and
in second input field (end time) 1:45 PM and on click
in third input field time should be 01:45
How can I make my code do that?
$('button').on('click', function() {
var timeOfCall = $('#timeOfCall').val(),
timeOfResponse = $('#timeOfResponse').val(),
hours = timeOfResponse.split(':')[0] - timeOfCall.split(':')[0],
minutes = timeOfResponse.split(':')[1] - timeOfCall.split(':')[1];
minutes = minutes.toString().length < 2 ? '0' + minutes : minutes;
if (minutes < 0) {
hours--;
minutes = 60 + minutes;
}
hours = minutes.toString().length < 2 ? '0' + hours : hours;
$('#delay').val(hours + ':' + minutes);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type="time" id="timeOfCall">
<input type="time" id="timeOfResponse">
<button>CLICK</button>
<input type="time" id="delay">