Total Time Elapased Calculation
I have start time 7:00 AM and end time 7:00 PM.For example: If I subtract 31st March 2015 7:30 AM with 30th March 2015 6:30 PM I want the result to display as 1 Hour and not 13 Hours. I want the start and end time to be used as I have defined and not the whole 24 Hours cycle. Please let me know if this can be done. If someone can share some code ir any links that would be great.
This script gets the date and return the years elapsed (like the age of someone).
$date=“2015-04-10”;
list($year,$month,$day)=explode(‘-’,$date);
$today=mktime(0,0,0,date(’m'), date(’d'),date(‘Y’));
$born=mktime(0,0,0,$month,$day,$year);
$years_old=floor(($today-$born)/60/60/24/365.25); // /60 -> minutes /60 -> hours /24 -> day /365.25 -> year
echo $years_old;
This script is PHP.
I don’t understand you asked, because I don’t speak english. But I hope that it helps you.
?
Things to consider: is the time period the same every day (i.e. 7am-7pm every day of the year)? Do you want to be able to compare between dates that are not consecutive? What result do you want if times outside those hours are used? (e.g. 2015-03-31 9pm - 2015-03-25 3am).
If the start of the time period is always the same (7am) a first step would be just to subtract 7 from the hours (and clamp negative results to 0). Oh and work with 24 hour clock.
Here, have some shitty pseudocode (with the limits hardcoded in):
```
getcrazyhours(time a, time b){ // a - b
// adjust hours
if (a.hours>19) a.hours= 19;
if (b.hours>19) b.hours= 19;
a.hours -= 7;
if (a.hours<0) a.hours= 0;
b.hours -= 7;
if (b.hours<0) b.hours= 0;
days= a.date - b.date; // date without hours
hours= days * 12 + a.hours - b.hours; // if a is earlier in the day than b the hours part will be negative but that is correct
return hours;
}
```
Now, if you want different time periods on different days then I think you’d have to step through the dates between a and b adding on the hours for each (unless it was in a very predictable format, like different on weekends).
This is starting to sound a lot like “do my (home)work for me.”
[quote=tl0tr]Manually I just subtract the hours that I don’t need. Actually I don’t really know. When it comes to time conversion and stuffs then I get all confused.[/quote]
All the more reason to try and figure it out yourself. Take a structured approach, split it up in cases you can handle, get an actual calendar and figure out how you would do it manually, etc. Or at least ask help with figuring out how to approach this instead of just asking for the end result.
Also, try to be clear and complete when you ask questions. Put in that extra little bit of effort before hitting ‘send’ instead of expecting us to do that by figuring out what you mean (in addition to already helping you out by answering).
Actually I need this done in Excel but I am not sure if it can be done in Excel. I have huge amount of data and I want the Time Elapsed for all the data. I won’t able to do it one at a time it would take me ages but anyways thanks for help and advise everyone.
I am googling to see if this can be done in Excel.
If I get the answer I’ll post it.
For the time being I am keeping the thread open.