...

View Full Version : Calculate open hours



bugrake
09-11-2011, 05:27 PM
hi,
I have three variables
- string openTime format hh:mm - eg "08:30"
- string closeTime format hh:mm eg "17:30"
- float lunchHours eg 1.5

Are there any js functions I can use to calculate how many hours the shop is open ?

thanks

Old Pedant
09-11-2011, 11:05 PM
You could do it using methods of the Date object, but it's probably actually easier to "roll your own".



var openTime = "08:30";
var closeTime = "17:30";
var lunchHours = 1.5;

function convertToHours( timeString )
{
var temp = timeString.split(":");
return Number(temp[0]) + ( Number(temp[1]) / 60 );
}

var openHours = convertToHours(closeTime) - convertToHours(openTime) - lunchHours;

bugrake
09-12-2011, 05:20 PM
great - thank you :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum