deyvie Posted July 19, 2007 Share Posted July 19, 2007 Hello Everyone, I am currently making a script to compute how much time in minutes has elapsed between two timestamps, but the catch is I only need to compute for the time between 9:00AM to 6:00PM. I was already able to compute for the time difference if I do not consider the window from 9:00AM to 6:00PM. Does anyone have an idea on how I can incorporate the window? Ex. Start Time: July 19 2007 5:00PM End Time : July 20 2007 9:23AM Time Elapsed: 83 Minutes Thank you! deyvie Quote Link to comment Share on other sites More sharing options...
dooper3 Posted July 19, 2007 Share Posted July 19, 2007 Yeah, do it like this... $startstamp=123456789; $endstamp=987654321; $startmorning=mktime(9, 0, 0,date(j), date(n), date(Y)); $endevening=mktime(18, 0, 0, date(j), date(n), date(Y)); if ($startmorning > $startstamp) { $startstamp=$startmorning; } if ($endevening < $endstamp) { $endstamp=$endevening; } $validhours=$endstamp-$startstamp; So... what it's doing is working out the value of 9am and 6pm each day as a timestamp, and if the user's timestamp starts earlier than the 9am one, it takes the 9am one as the start of the day, and for the evening one if the user's one is bigger, it takes 6pm as the end of the day. It then calculates the difference between the start and end times and stores them in the timestamp $validhours. Should work but i haven't tested it as i'm at work. Obviously lots to do today! Quote Link to comment Share on other sites More sharing options...
deyvie Posted July 19, 2007 Author Share Posted July 19, 2007 Thanks dooper3! I'll give it a shot later (I'm at work as well..) and let you know how it turns out. deyvie Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.