1833873 Members
1916 Online
110063 Solutions
New Discussion

Date question addendum

 
SOLVED
Go to solution
Kris Spander
Advisor

Date question addendum

Hello again,

This is an addendum to my earlier date question. I've used A. Clay Stephenson's "date hammer" to fix part of my script. Now I have another question. Because we have offices located in several timezones, we need to get a date one week from the current date in GMT. We don't want to have to change the timezone on the server just to make this work. Based upon Clay's earlier answer, I have gotten this far:

CURRDATE_7=$(caljd.sh -e -S "-" $(caljd.sh -n 7))

The problem is that this is PDT and we need it to work in GMT.

Thanks in advance for your help,
Kris
Dilbert is my hero.
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Date question addendum

Hi Kris:

This is pretty easy. Remember that all UNIX boxes in the known universe keep time by simply
counting the number of seconds since the Earth was created - Jan. 1, 1970 UTC. The TZ setting only determines how the time is DISPLAYED in a given process's environment. You can simply do
an "export TZ=GMT0" before the call to caljd.sh
BUT it's even easier to do than that.

Simply change:
CURRDATE_7=$(caljd.sh -e -S "-" $(caljd.sh -n 7))
to:
CURRDATE_7=$(caljd.sh -e -S "-" $(caljd.sh -U -n 7))

The -U does exactly what you want.

P.S. You should have done a caljd.sh -u and read the usage message carefully. It would have told you this.

Regards, Clay


If it ain't broke, I can fix that.
Rodney Hills
Honored Contributor

Re: Date question addendum

caljd.sh is a great tool. But perl has some built in functions to work with GMT.

perl -e 'print scalar gmtime(time()+7*24*60*60)),"\n"'

will print the date 7 days in the future relative to GMT.

-- Rod Hills
There be dragons...
Kris Spander
Advisor

Re: Date question addendum

Thanks to both of you. Clay, I did a caljd.sh -u and now I feel really dumb. The answer was there all the time. I did a search on "caljd.sh" and I am absolutely amazed at the number of "hits" that I got. I really expected to see lots and lots of if's and case's in the calculations but they weren't there. That is some script!!!

Thanks again,
Kris
Dilbert is my hero.
A. Clay Stephenson
Acclaimed Contributor

Re: Date question addendum

Hi Kris:

I'm glad you liked the script. I really can't take credit for the calendar date to Julian Day
and the Julian Day to calendar date algorithms. Julian Days have been around a very long time and if you ever took an astrophysics course or an advanced mechanics course, you would have been introduced to them.
The algorithms I used are based on some that were published many years ago in 'Sky and Telescope' magazine. (If you are any kind of sky buff, you have a subscription.)

I just added some command-line parsing and holidays stuff to the existing algorithms.

Regards, Clay

If it ain't broke, I can fix that.