I am having some problems with trying to perform calculations on time
fields. Say I have a start time and an end time, 1:00:00 and 2:30:00
(on a 24 hour scale, not 12). I want to find the difference in minutes,
divide this result by a predefined size of interval, and make a loop
that runs this many times. For example, with an interval size of 15
minutes, it will return 6 blocks... I have this all working fine, but am
getting stuck on the next part.
Given the above assumptions, I want to insert 6 tuples into my MySQL
database:
start end
1:00:00 1:15:00
1:15:00 1:30:00
1:30:00 1:45:00
1:45:00 2:00:00
2:00:00 2:15:00
2:15:00 2:30:00
This is where it gets kind of tricky... I can accomplish for the most
part what I want with a lot of checks through if/else statements. Right
now I pull out the minute portion, check to see this value plus the
interval becomes greater than or equal to 60, and if it does I set it
equal to "00" and increment the hour portion... otherwise I simply add
the interval to the current minute value. The problem is this is
getting very messy and I keep finding new checks that I have to make...
I have been all over the web trying to find a solution but haven't had
any luck yet... I also checked out mysql related sites but since this is
all happening before querying the database, it's more of a PHP related
issue... there has to be some sort of functionality built in that allows
comparision of two times, i.e. just adding 15 minutes through a loop and
have the time formatted for you. Thanks so much in advance if anyone
knows of how to do this, or of a more efficient way to do what I'm trying.
Marcus
fields. Say I have a start time and an end time, 1:00:00 and 2:30:00
(on a 24 hour scale, not 12). I want to find the difference in minutes,
divide this result by a predefined size of interval, and make a loop
that runs this many times. For example, with an interval size of 15
minutes, it will return 6 blocks... I have this all working fine, but am
getting stuck on the next part.
Given the above assumptions, I want to insert 6 tuples into my MySQL
database:
start end
1:00:00 1:15:00
1:15:00 1:30:00
1:30:00 1:45:00
1:45:00 2:00:00
2:00:00 2:15:00
2:15:00 2:30:00
This is where it gets kind of tricky... I can accomplish for the most
part what I want with a lot of checks through if/else statements. Right
now I pull out the minute portion, check to see this value plus the
interval becomes greater than or equal to 60, and if it does I set it
equal to "00" and increment the hour portion... otherwise I simply add
the interval to the current minute value. The problem is this is
getting very messy and I keep finding new checks that I have to make...
I have been all over the web trying to find a solution but haven't had
any luck yet... I also checked out mysql related sites but since this is
all happening before querying the database, it's more of a PHP related
issue... there has to be some sort of functionality built in that allows
comparision of two times, i.e. just adding 15 minutes through a loop and
have the time formatted for you. Thanks so much in advance if anyone
knows of how to do this, or of a more efficient way to do what I'm trying.
Marcus
Comment