Re: [PHP] Calculate # of minutes during working hours between two dates
Yick! Three-quarters of the replies to this are not what he asked for, and the others are really scarily inefficient. Total work time = (start time to end of first week) + (end of first week to end of last week) - (end time to end of last week). This is a non-obvious way to phrase it, but it eliminates the special case where the start and end dates are in the same week, and it ensures that the first and last clauses are formed in the same way, ie can be implemented as calls to the same function. So it becomes $worktime = to_end_of_week($start) + per_week*(week($end) - week($start)) - to_end_of_week($end); I wrote up a demo; you can visit it at http://www.bothwellmedia.com/worktime.php "Wim Koorenneef" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Hi all, > > I want to calculate the number of minutes between two dates, but only > those minutes on monday through friday between 08.00 and 17.30. > > I could evaluate every minute in the interval against all known minutes > during working hours, but that's a bit much :-) Any suggestions for a > better, more efficient algorithm? Tia. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Calculate # of minutes during working hours between two dates
You'll also need to calculate: * the number of minutes from the start time to 17:30 * the number of minutes from the 8:00 to the end time * the number of weekends between the times -- Jason Murray [EMAIL PROTECTED] Web Developer, Melbourne IT "What'll Scorpy use wormhole technology for?" 'Faster pizza delivery.' > -Original Message- > From: SED [mailto:[EMAIL PROTECTED]] > Sent: Thursday, June 21, 2001 5:55 AM > To: 'Wim Koorenneef' > Cc: [EMAIL PROTECTED] > Subject: RE: [PHP] Calculate # of minutes during working hours between > two dates > > > Try to find unix-time in seconds: (endtime - starttime) / 60 = total > minutes > > SED > > -Original Message- > From: Wim Koorenneef [mailto:[EMAIL PROTECTED]] > Sent: 20. júní 2001 15:26 > To: [EMAIL PROTECTED] > Subject: [PHP] Calculate # of minutes during working hours between two > dates > > > Hi all, > > I want to calculate the number of minutes between two dates, but only > those minutes on monday through friday between 08.00 and 17.30. > > I could evaluate every minute in the interval against all > known minutes > during working hours, but that's a bit much :-) Any suggestions for a > better, more efficient algorithm? Tia. > > -- > Greetinx, > > Wim Koorenneef <[EMAIL PROTECTED]> Boxtel, the Netherlands > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] To > contact the list administrators, e-mail: [EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: > [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Calculate # of minutes during working hours between two dates
this is just the way I would do it: generate timestamps for 8.00 and 17.30 for the days you want as long as the timestamps are between the two original timestamps. after that it's all subtraction and dividing by 60. That's about as efficient as I can think of. Rich Cavanaugh -Original Message- From: Wim Koorenneef [mailto:[EMAIL PROTECTED]] Sent: Wednesday, June 20, 2001 11:26 AM To: [EMAIL PROTECTED] Subject: [PHP] Calculate # of minutes during working hours between two dates Hi all, I want to calculate the number of minutes between two dates, but only those minutes on monday through friday between 08.00 and 17.30. I could evaluate every minute in the interval against all known minutes during working hours, but that's a bit much :-) Any suggestions for a better, more efficient algorithm? Tia. -- Greetinx, Wim Koorenneef <[EMAIL PROTECTED]> Boxtel, the Netherlands -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Calculate # of minutes during working hours between two dates
Hi See http://www.php.net/manual/en/function.jddayofweek.php For each date returning 1 through 5, add the appropriate amounts of minutes to the total HTH Wim Koorenneef wrote: > Hi all, > > I want to calculate the number of minutes between two dates, but only > those minutes on monday through friday between 08.00 and 17.30. > > I could evaluate every minute in the interval against all known minutes > during working hours, but that's a bit much :-) Any suggestions for a > better, more efficient algorithm? Tia. > > -- > Greetinx, > > Wim Koorenneef <[EMAIL PROTECTED]> Boxtel, the Netherlands > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Calculate # of minutes during working hours between two dates
figure out how many minutes per day, put that as a constant in your script, then just multiply that by the number of days between the two dates. ... or would you prefer something more convoluted? ;) > -Original Message- > From: Wim Koorenneef [mailto:[EMAIL PROTECTED]] > Subject: [PHP] Calculate # of minutes during working hours between two > dates > > Hi all, > > I want to calculate the number of minutes between two dates, but only > those minutes on monday through friday between 08.00 and 17.30. > > I could evaluate every minute in the interval against all known minutes > during working hours, but that's a bit much :-) Any suggestions for a > better, more efficient algorithm? Tia. > > -- > Greetinx, > > Wim Koorenneef <[EMAIL PROTECTED]> Boxtel, the Netherlands -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Calculate # of minutes during working hours between two dates
Try to find unix-time in seconds: (endtime - starttime) / 60 = total minutes SED -Original Message- From: Wim Koorenneef [mailto:[EMAIL PROTECTED]] Sent: 20. júní 2001 15:26 To: [EMAIL PROTECTED] Subject: [PHP] Calculate # of minutes during working hours between two dates Hi all, I want to calculate the number of minutes between two dates, but only those minutes on monday through friday between 08.00 and 17.30. I could evaluate every minute in the interval against all known minutes during working hours, but that's a bit much :-) Any suggestions for a better, more efficient algorithm? Tia. -- Greetinx, Wim Koorenneef <[EMAIL PROTECTED]> Boxtel, the Netherlands -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Calculate # of minutes during working hours between two dates
sloppy psuedocode:(but you get the idea) numdays = date2 - date1 minperday = 60 * 9.5(hrs) totalminutes for interval = numdays * minperday - Original Message - From: "Wim Koorenneef" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, June 20, 2001 11:25 AM Subject: [PHP] Calculate # of minutes during working hours between two dates > Hi all, > > I want to calculate the number of minutes between two dates, but only > those minutes on monday through friday between 08.00 and 17.30. > > I could evaluate every minute in the interval against all known minutes > during working hours, but that's a bit much :-) Any suggestions for a > better, more efficient algorithm? Tia. > > -- > Greetinx, > > Wim Koorenneef <[EMAIL PROTECTED]> Boxtel, the Netherlands > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]