lioslios Posted June 27, 2014 Share Posted June 27, 2014 hello guys i wand to split the 24h of a day to parts and select the time that i wand to start the 24h circle to count! lets say i give 2 int variables $day_starts_to_count_from=00; $split_day_to_parts=4; so! $hours_per_part = 24/$split_day_to_parts; this gives me $hours_per_part = 6 (i split the 24h every 6hr) how to know the part of my current hour? lets say the system time is 15:35 how to find that im at the 3d part 12:00-18:00 if the 24h circle starts to count from 00:00 thanks in advance Quote Link to comment Share on other sites More sharing options...
.josh Posted June 27, 2014 Share Posted June 27, 2014 /* * @param $time string 24 hour time 'hh:mm' * @param $numParts int number of parts to split day cycle by * @return int day part */ function getDayPart($time, $numParts) { $numSeconds = 0; $secondsPerDay=24*60*60; $time=explode(':',$time); $numSeconds+=$time[0]*60*60; $numSeconds+=$time[1]*60; return floor(($numSeconds/$secondsPerDay)*$numParts)+1; } Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 27, 2014 Share Posted June 27, 2014 @lioslios: Do you need to consider the conversions to Daylight Savings to Standard Time? Are you OK with one day a year that the first 5 hours would be considered the first 4 hours and one day a year the first 3 hours would be considered the first four? If you had a block for 2 hours or less it would get really weird. It may not be a concern, but if this is something that is processed every day, depending on the usage, you may have to make allowances for it. Quote Link to comment Share on other sites More sharing options...
lioslios Posted June 27, 2014 Author Share Posted June 27, 2014 joshthank you verry much, its beter the fumction to return me the start and end time of the part also!, so if you can chenge, il be greatfull Psychoyou have write with daylight savings but i dont think is problem, but when i finish the entire script i emulate this to see how it goes Quote Link to comment Share on other sites More sharing options...
lioslios Posted June 27, 2014 Author Share Posted June 27, 2014 (edited) josh problem now i check better in the funcion i wand to know the part time i am by the current time of server the $day_starts_to_count_from is just an offset type (and set that the day dont change at the 00:00 night but 07:00 at morning! so the first of the 4 parts is 07:00-12:00 ) and if the server time is 11:00 then im at the first part!!!!! thanks Edited June 27, 2014 by lioslios Quote Link to comment Share on other sites More sharing options...
.josh Posted June 28, 2014 Share Posted June 28, 2014 lioslios that's not what you originally asked, not that you were being very clear to begin with, nor are you being entirely clear now. But in any case, we're not here to do your work for you. I've given you more than enough to point you in the right direction. You need to make an effort to do it yourself. If you get stuck on a specific thing, show what you've tried and what's wrong with it and we'll try to help. But If you want someone to do your work for you, I suggest you offer to pay for it (in the freelance section or on a freelance site). 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.