Unix Technical Forum

calculating with dates in aix 5.x

This is a discussion on calculating with dates in aix 5.x within the AIX Operating System forums, part of the Unix Operating Systems category; --> dear aix gurus, i'd like to calculate with dates (counting days between two dates). do you have a simple ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2008, 10:21 AM
tim moor
 
Posts: n/a
Default calculating with dates in aix 5.x

dear aix gurus,
i'd like to calculate with dates (counting days between two dates). do you
have a simple -> how to...

thanx alot
tim


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-05-2008, 10:21 AM
scott_doyland@johnlewis.co.uk
 
Posts: n/a
Default Re: calculating with dates in aix 5.x


tim moor wrote:
> dear aix gurus,
> i'd like to calculate with dates (counting days between two dates). do you
> have a simple -> how to...
>
> thanx alot
> tim


Could you perhaps use the Julain date and work it out that way. Youd
have to be careful when crossing over the years though - you'd prob
have to do something like this for counting backwards across a year:

julian date today - julian date last year + 365

Scott

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-05-2008, 10:21 AM
Mark Taylor
 
Posts: n/a
Default Re: calculating with dates in aix 5.x

> tim moor wrote:
> > dear aix gurus,
> > i'd like to calculate with dates (counting days between two dates). do you
> > have a simple -> how to...


Not that simple I am affraid .. I use perl generally and work in epoch
seconds then convert back into a real time stamp once the calcs are
done

NB: if you keep dropping into perl from the shell it will be forky ..
so, best to write it all in perl ..

The following will be of use for you :

POSIX qw(strftime)
scalar localtime(shift)
Time::Local timelocal_nocheck

Do a google for those and you will get some examples ..

HTH
Mark Taylor

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-05-2008, 10:21 AM
Hajo Ehlers
 
Posts: n/a
Default Re: calculating with dates in aix 5.x


tim moor wrote:
> dear aix gurus,
> i'd like to calculate with dates (counting days between two dates). do you
> have a simple -> how to...
>


From: Matthew Landt Mon, Aug 27 2001 4:49 pm in c.u.a

#!/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)))"


hth
Hajo

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-05-2008, 10:21 AM
Paul Pluzhnikov
 
Posts: n/a
Default Re: calculating with dates in aix 5.x

"tim moor" <tim.moor@nospam.com> writes:

> i'd like to calculate with dates (counting days between two dates). do you
> have a simple -> how to...


From http://www.unixwiz.net/tools/datemath.html

Too many times we have needed to do a bit of math on a date --
say, "today + 7 days" -- but in traditional MM/DD/YYYY format
this is really tricky (especially in a shell script). A result
of this need we built the datemath tool which can perform these
functions from the command line or from a shell script. Examples:

$ datemath today + 5
06/23/2003

$ datemath '12/25/2003 - today'
188

$ datemath today + 5 weeks
07/25/2003

when will my machine be up for one year?
$ uptime
11:09am up 317 days, 15:38, 7 users, load average: 0.16, 0.04, 0.01
$ datemath today + 365 - 317
10/24/2003


Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-05-2008, 10:21 AM
Hemant Shah
 
Posts: n/a
Default Re: calculating with dates in aix 5.x

While stranded on information super highway tim moor wrote:
> dear aix gurus,
> i'd like to calculate with dates (counting days between two dates). do you
> have a simple -> how to...
>
> thanx alot
> tim
>
>


Take look at GNU date.

Here are some examples from it's documentation:

To print the date of the day before yesterday:
date --date='2 days ago'

To print the date of the day three months and one day hence:
date --date='3 months 1 day'

To print the day of year of Christmas in the current year:
date --date='25 Dec' +%j


--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-05-2008, 10:23 AM
VinceM
 
Posts: n/a
Default Re: calculating with dates in aix 5.x

Try here:

http://www.samag.com/documents/s=828...307b/0307b.htm

Not simple, but the worthwhile seldom are.


"tim moor" <tim.moor@nospam.com> wrote in message
news:44fd37d9$1_7@news.bluewin.ch...
> dear aix gurus,
> i'd like to calculate with dates (counting days between two dates). do you
> have a simple -> how to...
>
> thanx alot
> tim
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:16 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com