Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Calculating date difference in days

Posted on 2001-07-28
Medium Priority
225 Views
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
Question by:markx
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 6

Accepted Solution

bira earned 200 total points
ID: 6330441
Hi

Use this script

#!/bin/ksh
clear
echo "Enter the first date in the format: YYYYMMDD:"
echo "Example:  20010731"
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"
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

ID: 6330445
i am interested. please inform me
0

Author Comment

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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.
###### Suggested Courses
Course of the Month5 days, 11 hours left to enroll