Sponsored Content
Top Forums Shell Programming and Scripting How to calculate specific hours between 2 dates Post 302218491 by joeyg on Friday 25th of July 2008 10:07:13 AM
Old 07-25-2008
Tools just thinking out loud on this - no real code yet

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.


Code:
curr_day = day1
while [ curr_day .le day2 ]
  do
  if [ day_of_wk in {MTWTF} ]
    then
#assume full day; hours in hundreds; over-write as needed
    day_hr=900
    if [ curr_day .eq day1 ]
      then
      day_hr=(1800 - day1(hr))
    fi
    if [ curr_day .eq day2 ]
      then
      day_hr=(day2(hr) - 900)
    fi
    hr_tot=(hr_tot + day_hr)
  fi
  curr_day=(curr_day+1)
done

 

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
SIP(4)							   BSD Kernel Interfaces Manual 						    SIP(4)

NAME
sip -- SiS 900-based Ethernet driver SYNOPSIS
sip* at pci? dev ? function ? Configuration of PHYs is also necessary. See mii(4). DESCRIPTION
The sip device driver supports Ethernet interfaces based on the Silicon Integrated Systems SiS 900, SiS 7016, and National Semiconductor DP83815 Ethernet chips. The SiS 900 is found on many motherboards featuring SiS chipsets, and on some embedded systems, and has a built-in PHY. The SiS 7016 is an older version of the chip, which uses an external PHY. The National Semiconductor DP83815 is found on NetGear FA-311 and FA-312 Ethernet boards, and has a built-in PHY. SEE ALSO
arp(4), ifmedia(4), mii(4), netintro(4), pci(4), ifconfig(8) HISTORY
The sip driver first appeared in NetBSD 1.5. AUTHORS
The sip driver was originally written by Jason R. Thorpe for Network Computer, Inc. It has since been modified by Jason R. Thorpe <thorpej@NetBSD.org> and Allen Briggs <briggs@NetBSD.org>. BSD
May 17, 2001 BSD
All times are GMT -4. The time now is 06:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy