Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Calculating date difference in days

a while ago, i calculated the difference between two dates in days and now i can't remember how i did it.

any help is appreciated.

thanks, mark
0
markx
Asked:
markx
1 Solution
 
biraCommented:
Hi

   Use this script

#!/bin/ksh
clear
echo "Enter the first date in the format: YYYYMMDD:"
echo "Example:  20010731"
read first
year=`echo $first |cut -c1-4`
month=`echo $first |cut -c5-6`
day=`echo $first |cut -c7-9`
let x1=0+(1461*(year+4800+(month-14)/12))/4+(367*(month-2-12*((month-14)/12)))/12
let w=0+(3*((year+4900+(month-14)/12)/100))/4
let x1=x1-w+day-32075
echo "Enter the second  date in the format: YYYYMMDD:"
echo "Example:  20010820"
read first
year=`echo $first |cut -c1-4`
month=`echo $first |cut -c5-6`
day=`echo $first |cut -c7-9`
let x2=0+(1461*(year+4800+(month-14)/12))/4+(367*(month-2-12*((month-14)/12)))/12
let w=0+(3*((year+4900+(month-14)/12)/100))/4
let x2=x2-w+day-32075
let z=x2-x1
echo "Here is the number of days between the 2 dates:" $z


 Regards
0
 
leolkkCommented:
i am interested. please inform me
0
 
markxAuthor Commented:
this script works great.  thanks for your help.  mx
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now