Jump to content

Manipulating Times


ibanez270dx

Recommended Posts

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
Link to comment
Share on other sites

And just so It's clear...I mean the hours that are submitted. Make sure they go into your database as a timestamp (11457688) , and not a formatted time (Such as 04:00 PM). You can do the formatting whenever you need to display or compare times.
Link to comment
Share on other sites

that works great! The only thing is that the minutes don't work... here is the code, I had to debug it a bit: Any reason why the minutes wouldn't work?

[code=php:0]
$mnt_start = '02:00';
$mnt_end  = '13:30';

$op_start = '05:00';
$op_end  = '23:00';

$downtime_start = max($mnt_start, $op_start);
$downtime_end = min($mnt_end, $op_end);

$display = ($downtime_end-$downtime_start);
[/code]
Link to comment
Share on other sites

As a value like "08:30" is a string, iys numeric value is 8 (':' is non-numeric so anything after that is ignored);

If you want the downtime in hours:minutes, try

[code]<?php
$mnt_start = '02:00';
$mnt_end  = '13:30';

$op_start = '05:00';
$op_end  = '23:00';

$downtime_start = max($mnt_start, $op_start);
$downtime_end = min($mnt_end, $op_end);

$dt_start = strtotime($downtime_start);
$dt_end = strtotime($downtime_end);

$mins = ($dt_end - $dt_start)/60;

$dt_hrs = floor($mins/60);
$dt_mins = $mins % 60;

echo $downtime_start, '-', $downtime_end, '<br>';
echo "Downtime : $dt_hrs:$dt_mins" ;
?>[/code]
Link to comment
Share on other sites

This is what I ended up with, and it works:  :) Thanks for your help!!!

[code=php:0]
$dt1 = "$dwntime_year $dwntime_month $dwntime_day";
$dt2 = str_replace(' ', '', $dt1);

$op_start = '05:00';
$op_end  = '23:00';

$downtime_start = max($dwntime_hrs1, $op_start);
$downtime_end = min($dwntime_hrs2, $op_end);

$dt3 = "$dt2 $downtime_start";
$dt4 = "$dt2 $downtime_end";

$downtime_hrs_start = strtotime($dt3);
$downtime_hrs_end = strtotime($dt4);

$dwntime_hrs = ($downtime_hrs_end-$downtime_hrs_start)/3600;
[/code]
Link to comment
Share on other sites

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.