Half day

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
jauson
Forum Contributor
Posts: 111
Joined: Wed Oct 05, 2011 12:59 am

Half day

Post by jauson »

Hi Brother,

this is regarding half day between two dates, assumed my start work is 8:00am and ends to 5:00pm, and a total of worked is 9 hours a day, including 12:00pm to 1:00pm breaktime. now, here's the code for 24 hours calculation.

<script type="text/javascript">
function getdate()
{
var one_day=1000*60*60*24;
var fdate = document.getElementById("textFromDate").value;
var tdate = document.getElementById("textToDate").value;

var date1=new Date(fdate);
var date2=new Date(tdate);
if(date1>date2)
{
alert("Date not possible. Choose another date.");
}
else{


var Diff=Math.ceil((date2.getTime()-date1.getTime())/one_day);

document.getElementById("textTotalDays").value=Diff+1;
}
}
</script>

I cannot explain well to you sorry. Please understand. :( but what i want to do


SAMPLE1.

if i select june132012 8:00am in datepicker1
and i select june132012 12:00pm in datepicker2
the result show like this.

4 / hours


SAMPLE2.

if i select june132012 8:00am in datepicker1
and i select june132012 5:00pm in datepicker2
the result show like this.

8 / hours(not including the break time)

help would be appreciated, thank you.
Post Reply