Sonja
Old but maybe useful post I archived
Matthew Landt <.....@ibm.com> wrote:
Here is a method that was posted a while ago. I took that function
and added my formatting and abiltiy to change for a couple of date
formats. I already uncommented the format you suggest.
- Matt
#!/bin/ksh
###########################################################################
# Date calculations using Korn shell (ksh88)
# Tapani Tarvainen July 1998, May 2000
# This code is in the public domain.
# Julian Day Number from calendar date
date2julian() # day month year
{
typeset -i day month year tmpmonth tmpyear
day=$1; month=$2; year=$3
((tmpmonth = 12 * year + month - 3))
((tmpyear = tmpmonth / 12))
print $(( (734 * tmpmonth + 15) / 24 - 2 * tmpyear + \
tmpyear/4 - tmpyear/100 + tmpyear/400 + day + 1721119 ))
}
###
# Matt's Added formatting
###
# Store input dates
date1=$1
date2=$2
# Get the dates into their respective fields. Uncomment the format of
# date input being used.
# YYYYMMDD
#year1=${date1%????}
# mmdd1=${date1#????}
# month1=${mmdd1%??}
# day1=${mmdd1#??}
#year2=${date2%????}
# mmdd2=${date2#????}
# month2=${mmdd2%??}
# day2=${mmdd2#??}
# YYYY/MM/DD or YYYY/M/D
#print $date1 |IFS=/ read year1 month1 day1
#print $date2 |IFS=/ read year2 month2 day2
# MM/DD/YY or M/D/YYYY
#print $date1 |IFS=/ read month1 day1 year1
#print $date2 |IFS=/ read month2 day2 year2
# DD/MM/YY or M/D/YYYY
print $date1 |IFS=/ read day1 month1 year1
print $date2 |IFS=/ read day2 month2 year2
# Calculate and print the difference between dates (date2 - date1)
print -- "$(($(date2julian $day2 $month2 $year2) -
$(date2julian $day1 $month1 $year1)))"
--
Alberto 'JCN-9000' Varesio AKA BlueRider AIX pSeries System Admin
Datavision PLM - Tel: +390117710276 Biker on HONDA CB500 - LHG
http://www.datavisionplm.com Jeeper on Sport TJ - Wave
Please http://www.fsf.org/philosophy/no-word-attachments.html, thanks!
==
BOFH Excuse: We already sent around a notice about that.
gnudate +'%s' will give current epoch seconds, is this what you want
? you could use perl Time::Local 'timelocal_nocheck' can also do the
calculations for you if you want to convert the output of the ls -l
command or a TSM backup timestamp etc... check out the docs.
Rgds
Mark Taylor
perl -we "print time"
1078411396
bc
1078411396+86400
1078497796
perl -we "print scalar localtime 1078411396"
Thu Mar 4 08:43:16 2004
perl -we "print scalar localtime 1078497796"
Fri Mar 5 08:43:16 2004
I have some standalone "C" programs I created years ago to do this,
but I use perl now where possible.
BV