Sponsored Content
Top Forums Shell Programming and Scripting How to calculate specific hours between 2 dates Post 302218503 by sickboy on Friday 25th of July 2008 10:35:32 AM
Old 07-25-2008
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

Code:
    if (startdate.day_of_week in (5,6)) or (startdate.day_of_week == 4 and startdate.hour > 18):
        print 'I am in the first if'
        while True:
            startdate = startdate + mx.DateTime.RelativeDateTime(days=+1)
            print startdate.day_of_week
            if startdate.day_of_week == 0:
                startdate = startdate + mx.DateTime.RelativeDateTime(hour=9,minute=0,second=0)
                break
    elif startdate.day_of_week in (0,1,2,3,4) and startdate.hour < 9:
        startdate = startdate + mx.DateTime.RelativeDateTime(hour=9,minute=0,second=0)
    elif startdate.day_of_week in (0,1,2,3) and startdate.hour > 18:
        startdate = startdate + mx.DateTime.RelativeDateTime(days=+1,hour=9,minute=0,second=0)

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

Last edited by sickboy; 07-25-2008 at 11:50 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate days between yyyyMmmdd dates on Solaris

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)
Discussion started by: djanu
4 Replies

2. Web Development

Calculate the number of days between 2 dates - PHP

Is this code good for this purpose? <?php $date1 = mktime(0,0,0,01,01,1991); $date2 = mktime(0,0,0,03,22,2012); $diff = $date2 - $date1; $days = $diff / (60*60*24); echo ($days . "<br />"); ?> (3 Replies)
Discussion started by: kovacsakos
3 Replies

3. Shell Programming and Scripting

Calculate the number of days between 2 dates - bash script

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)
Discussion started by: kovacsakos
3 Replies

4. Shell Programming and Scripting

How to Calculate the difference between two dates?

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)
Discussion started by: m_raheelahmed
1 Replies

5. Shell Programming and Scripting

Shell script to calculate difference between 2 dates

shell script to calculate difference between 2 dates (3 Replies)
Discussion started by: gredpurushottam
3 Replies

6. Shell Programming and Scripting

Calculate time difference between pst and pdt dates in perl

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)
Discussion started by: praveen265
3 Replies

7. Shell Programming and Scripting

Collect files for specific hours

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)
Discussion started by: Saidul
1 Replies

8. UNIX for Advanced & Expert Users

How to get ALL update dates and hours of a file?

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)
Discussion started by: nurinolo
3 Replies

9. Shell Programming and Scripting

Find hours difference between two dates in given format

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)
Discussion started by: simpltyansh
3 Replies

10. Red Hat

Delete files older than 1week(dates need to be calculate based on file name)

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)
Discussion started by: Agoyals1986
2 Replies
IPSEC_OPENAC(8) 					      System Manager's Manual						   IPSEC_OPENAC(8)

NAME
ipsec openac - Generation of X.509 attribute certificates SYNOPSIS
ipsec openac [ --help ] [ --version ] [ --optionsfrom filename ] [ --quiet ] [ --debug level ] [ --days days ] [ --hours hours ] [ --startdate YYYYMMDDHHMMSSZ ] [ --stopdate YYYYMMDDHHMMSSZ ] --cert certfile --key keyfile [ --password password ] --usercert certfile --groups attr1,attr2,... --out filename DESCRIPTION
openac is intended to be used by an Authorization Authority (AA) to generate and sign X.509 attribute certificates. Currently only the inclusion of one ore several group attributes is supported. An attribute certificate is linked to a holder by including the issuer and serial number of the holder's X.509 certificate. OPTIONS
--help display the usage message. --version display the version of openac. --optionsfrom filename adds the contents of the file to the argument list. If filename is a relative path then the file is searched in the directory /etc/openac. --quiet By default openac logs all control output both to syslog and stderr. With the --quiet option no output is written to stderr. --days days Validity of the X.509 attribute certificate in days. If neiter the --days nor the --hours option is specified then a default valid- ity interval of 1 day is assumed. The --days option can be combined with the --hours option. --hours hours Validity of the X.509 attribute certificate in hours. If neiter the --hours nor the --days option is specified then a default valid- ity interval of 24 hours is assumed. The --hours option can be combined with the --days option. --startdate YYYYMMDDHHMMSSZ defines the notBefore date when the X.509 attribute certificate becomes valid. The date YYYYMMDDHHMMSS must be specified in UTC (Zulu time). If the --startdate option is not specified then the current date is taken as a default. --stopdate YYYYMMDDHHMMSSZ defines the notAfter date when the X.509 attribute certificate will expire. The date YYYYMMDDHHMMSS must be specified in UTC (Zulu time). If the --stopdate option is not specified then the default notAfter value is computed by adding the validity interval speci- fied by the --days and/or --days options to the notBefore date. --cert certfile specifies the file containing the X.509 certificate of the Authorization Authority. The certificate is stored either in PEM or DER format. --key keyfile specifies the encrypted file containing the private RSA key of the Authoritzation Authority. The private key is stored in PKCS#1 format. --password password specifies the password with which the private RSA keyfile defined by the --key option has been protected. If the option is missing then the password is prompted for on the command line. --usercert certfile specifies file containing the X.509 certificate of the user to which the generated attribute certificate will apply. The certificate file is stored either in PEM or DER format. --groups attr1,attr2 specifies a comma-separated list of group attributes that will go into the X.509 attribute certificate. --out filename specifies the file where the generated X.509 attribute certificate will be stored to. Debugging openac produces a prodigious amount of debugging information. To do so, it must be compiled with -DDEBUG. There are several classes of debugging output, and openac may be directed to produce a selection of them. All lines of debugging output are prefixed with ``| '' to distinguish them from error messages. When openac is invoked, it may be given arguments to specify which classes to output. The current options are: --debug level sets the debug level to 0 (none), 1 (normal), 2 (more), 3 (raw), and 4 (private), the default level being 1. EXIT STATUS
The execution of openac terminates with one of the following two exit codes: 0 means that the attribute certificate was successfully generated and stored. 1 means that something went wrong. FILES
/etc/openac/serial serial number of latest attribute certificate SEE ALSO
The X.509 attribute certificates generated with openac can be used to enforce group policies defined by ipsec.conf(5). Use ipsec_auto(8) to load and list X.509 attribute certificates. For more information on X.509 attribute certificates, refer to the following IETF RFC: RFC 3281 An Internet Attribute Certificate Profile for Authorization HISTORY
The openac program was originally written by Ariane Seiler and Ueli Galizzi. The software was recoded by Andreas Steffen using strongSwan's X.509 library and the ASN.1 code synthesis functions written by Christoph Gysin and Christoph Zwahlen. All authors were with the Zurich University of Applied Sciences in Winterthur, Switzerland. BUGS
Bugs should be reported to the <users@lists.strongswan.org> mailing list. 22 September 2007 IPSEC_OPENAC(8)
All times are GMT -4. The time now is 02:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy