Manipulating Times

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ibanez270dx
Forum Commoner
Posts: 74
Joined: Thu Jul 27, 2006 12:06 pm
Location: Everywhere, California

Manipulating Times

Post by ibanez270dx »

Hi,
I have run into a problem in a program I'm writing for my client... Heres the story:

I am developing a system that logs the downtime of aircraft due to many different reasons. One of them is maintenance. The maintenance work is based on a 24 hour day. Thus, the log is based on a 24 hour time scale where a user can log a downtime (ex: 05:00 to 14:30). However, the hours of operation for these aircraft is based on an 18 hour day (05:00 to 23:00). What I need to do is to be able to take a 24hr day maintenance log and convert it to an 18hr day to log the downtimes in operation.

Here is an example: Let's say that the aircraft is down for maintenance between the hours of 01:00 and 08:00. I need to convert this 24 hour scale to an 18 hour scale. In actuallity, I need to take the overlapping hours and store them in a variable. The hours of operation are 05:00 to 23:00, thus with the example of 01:00 to 08:00, I would count 05:00 to 08:00. How would I do that?

Its kinda confusing, I know, but any help is greatly appreciated!!!!

Thank you!
- Jeff
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Some rough code

Code: Select all

$timeDiff = $timeEnd - $timeStart;
$eighteenHours = 18 * 3600;
$days = floor($timeDiff / $eighteenHours);
$remainder = $timeDiff % $eighteenHours;
ibanez270dx
Forum Commoner
Posts: 74
Joined: Thu Jul 27, 2006 12:06 pm
Location: Everywhere, California

Post by ibanez270dx »

Thanks for the code! Could you maybe explain it? I don't really know whats going on in it...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$timeEnd and $timeStart are unix timestamps of when the work ended and started, respectively. $eighteenHours is, well eighteen hours (in seconds, the unit of measure in unix timestamps.) $days is the number of eighteen hour days the work took. $remainder is any remaining time into the $days + 1 day.
ibanez270dx
Forum Commoner
Posts: 74
Joined: Thu Jul 27, 2006 12:06 pm
Location: Everywhere, California

Post by ibanez270dx »

this might sound stupid, but how do I go about converting my input (05:00) to a timestamp? I tried to use mktime($mytime) where $mytime = 05:00, but it just gives an output thats way off...

Thanks,
- Jeff
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

Code: Select all

mktime(5, 0, 0);
for today's 5am, check manual for more.
Post Reply