Solved

Calculating date difference in days

Posted on 2001-07-28
3
218 Views
Last Modified: 2010-04-21
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
Comment
Question by:markx
3 Comments
 
LVL 6

Accepted Solution

by:
bira earned 50 total points
ID: 6330441
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
 
LVL 1

Expert Comment

by:leolkk
ID: 6330445
i am interested. please inform me
0
 

Author Comment

by:markx
ID: 6330455
this script works great.  thanks for your help.  mx
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now