ibanez270dx Posted August 14, 2006 Share Posted August 14, 2006 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 More sharing options...
Caesar Posted August 14, 2006 Share Posted August 14, 2006 Store your hours as timestamps, and this will be easily achieved. Link to comment https://forums.phpfreaks.com/topic/17549-manipulating-times/#findComment-74733 Share on other sites More sharing options...
Caesar Posted August 14, 2006 Share Posted August 14, 2006 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 https://forums.phpfreaks.com/topic/17549-manipulating-times/#findComment-74736 Share on other sites More sharing options...
ibanez270dx Posted August 14, 2006 Author Share Posted August 14, 2006 ok, so if the user had to enter the hours manually like "05:00" or something, how would I convert that to a timestamp? I still don't know how I would be able to do it, even if it is stored as a timestamp... Can you explain? Link to comment https://forums.phpfreaks.com/topic/17549-manipulating-times/#findComment-74742 Share on other sites More sharing options...
Barand Posted August 14, 2006 Share Posted August 14, 2006 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 More sharing options...
ibanez270dx Posted August 14, 2006 Author Share Posted August 14, 2006 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 More sharing options...
Barand Posted August 14, 2006 Share Posted August 14, 2006 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 More sharing options...
ibanez270dx Posted August 14, 2006 Author Share Posted August 14, 2006 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.