I am trying to find out a way to calculate how many hours are between 2 dates but from a specific time range, actually working hours (Monday to Friday 09:00 - 18:00).
What I mean is for example
date1 = Monday 21 July 2008 22:00:00 so in python 2008-07-21 22:00:00
date2 = Wednesday 23 July 2008 12:00:00 so in python 2008-07-23 12:00:00
and I want to find a way to say
date2 - date1 = 12 hours
Always the date2 is in working hours.
Anybody has an idea how to do this? Actually I don't care about the programming language I just want to find the best logic to do this and then I will write it in python
Still some quirks below, like adjusting start & end times to 900 or 1800 (your input example was outside this range). However, perhaps this gives you a basis to begin thinking about a process.
I thought the same way, with multiple ifs and adjusting the starting date (the closing date is always within the working times) but I thought maybe there is a more effective way to do this.
Perhaps multiply the number of days difference by 9 (for 9 working hours) and subtract the working hours not included on the first day and last day? Similarly subtract 9 from days which are weekends.
There are other reasons to do this one day at a time:
(a) account for holidays, vacations
(b) allow for lookups when special conditions exist for a day
By this, think of a day as 20080725. Now, while inside your main loop, do the following; although with a $var and not a fixed #.
The file may contain various fields you could read, like
max_hrs=400 ;scheduled half day
max_hrs=0 ;no work day
etc..
Good one, but actually I don't want to take it so far. The only thing I will do is to subtract the weekends. I found a really interesting article how to find how many weekends are between two dates. http://dirtsimple.org/2004/10/nineteen-hundred-weekends.html
So what I thought so far is:
I have the startdate and the closing date.
I wrote this to adjust the startdate to working hours
but this is only if the startdate is out of the working hours.
It becomes harder when the starting date is for example 17:00. Then I have to keep this 1hour in a temp value calculate for the closing date and add it at the end.
Edit:
If the startdate is within the working times I guess I just have to subtract 15 hours
Objective: We have multiple files in a folder and we want to delete all files except for last 1 week files.
Note: We are copying these files from original location to this temporary location. So time shown for these files are time when we copied to this location. Not that when file was created.... (2 Replies)
I have two dates in below format, how would I find the hours difference between the two dates. Im using AIX and ksh.
Current date : Wed May 17 14:34:41 SGT 2017
File date : Thu Apr 27 20:52:41 SGT 2017 (3 Replies)
Hello,
I have a question please,
How could I get ALL update dates and hours of a file ?
For example:
I modified a file on 09/04/2014 at 7:am for the first time. Then, I modified again the same file on 09/04/2014 at 9 am and finally, I modified the same file again on 10/04/2014 at... (3 Replies)
I have to fetch files from a location hour wise.
Eg files available at location /tmp/data/ are
A20140205.1300-1315......
.
.
A20140205.1400-1415......
.
.
A20140205.1700-1715......
.
.
.
.
Below is the code I have prepared.
But it works only for one hour.
For instance... (1 Reply)
Hi,
how to calculate the time difference between PST date and PDT date in perl scripting.
date1: Mon Dec 31 16:00:01 PST 2015
date2: Tue Mar 19 06:09:30 PDT 2013
and also difference between PST-PST and PDT-PDT
need difference in months or days (months prefereble). (3 Replies)
I want the difference between two following date using scripts in terms of no.of days. How I can accomplish this.
lastdate=Tue Nov 13 10:30:56 2012
currdate=Wed Dec 15 15:58:21 PAKST 2012
Ouput should be like this:
Your Password will expire after = 32 Days on Wed Dec 15 15:58:21 PAKST... (1 Reply)
I wrote the day calculator also in bash. I would like to now, that is it good so?
#!/bin/bash
datum1=`date -d "1991/1/1" "+%s"`
datum2=`date "+%s"`
diff=$(($datum2-$datum1))
days=$(($diff/(60*60*24)))
echo $days
Thanks in advance for your help! (3 Replies)
I extract dates from the log file and need to calculate days between two dates. My dates are in yyyyMmmdd format. Example:
$d1=2011 Oct 21
$d2=2012 Feb 20
I need to calculate the number of days between $d2 and $d1. This is on Solaris.
Any ideas?
Thanks,
djanu (4 Replies)