Jump to content

Recommended Posts

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

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/289298-split-day-to-parts-and-check/
Share on other sites


/*
* @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;
}

@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.

josh

thank 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

 

 

 

Psycho

you 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

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 by lioslios

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.