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
https://forums.phpfreaks.com/topic/17549-manipulating-times/
Share on other sites

try
[code]<?php

$mnt_start = '18:00';
$mnt_end  = '23:30';

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

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

echo "$downtime_start - $downtime_end";
?>  [/code]
Link to comment
https://forums.phpfreaks.com/topic/17549-manipulating-times/#findComment-74794
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
https://forums.phpfreaks.com/topic/17549-manipulating-times/#findComment-74811
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
https://forums.phpfreaks.com/topic/17549-manipulating-times/#findComment-74819
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
https://forums.phpfreaks.com/topic/17549-manipulating-times/#findComment-74830
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.