1834644 Members
3144 Online
110069 Solutions
New Discussion

Re: Script Help

 
SOLVED
Go to solution
Nobody's Hero
Valued Contributor

Script Help

I am using 'ex' within a script. I read in a file and use 'ex' to cut out what I need. My question is, I have this command as a variable
date '+%m\/%d\/%y' and my output looks like
02\/06\/02.

How can I use this same method to get tomorrows date in the form 02/07/02. I dont need the back slash in 'tomorrows date' output.


Thanks,
Bob
UNIX IS GOOD
10 REPLIES 10
melvyn burnard
Honored Contributor

Re: Script Help

running date +%m%d%y gives me 020602.
Is that what you are after?
Remove the \/ from your script and see if that helps.

My house is the bank's, my money the wife's, But my opinions belong to me, not HP!
Kurtkarl
Frequent Advisor

Re: Script Help

hi,

try this
x=`date +%m"/"%d"/"%y`;echo $x

Hope this help
jose
Just starting to learn thru this forum
Andreas Voss
Honored Contributor
Solution

Re: Script Help

Hi,

to get next day you could do:

TZ=GMT+24 date +%m/%d/%y

Regards
Darrell Allen
Honored Contributor

Re: Script Help

Hi Bob,

A. Clay Stephenson has contributed the attached script on a number of occasions. It can be used to convert to and from Julian dates which makes date math simple. To get tomorrow's date in the form mmddyy:

caljd.sh `caljd.sh -n1` | sed 's/ //g' | cut -c1-4,7-8

If you do want / delimited:

caljd.sh `caljd.sh -n1` | sed 's/ /\//g' | cut -c1-6,9-10

All the credit to Clay.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Craig Rants
Honored Contributor

Re: Script Help

I run the date command and put it into a variable, resulting in the output you want. Here is what I do.

DATE=`date +%m/%d/%y`

GL,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
James R. Ferguson
Acclaimed Contributor

Re: Script Help

Hi Robert:

I have used the trick noted by Andreas, too. However, if you want the date *exactly* 24-hours from your current date; that is, exactly the *next* day, you need to account for the difference you are from UTC.

Thus, in my US Eastern time zone, I am 5 hours earlier than UTC. Thus, if I want tomorrow's date I specify (24 - 5 or 19 hours from now):

# TZ=EST-19 date

Note that this only works for offsets less than 24-hours so these tricks work only for one day offsets.

Note too, the blank after the TZ variable is set. There is no semicolon either! This syntax sets the TZ variable *only* for this command line.

Regards!

...JRF...
Darrell Allen
Honored Contributor

Re: Script Help

That's a neat idea Andreas! James, good add-on about adjusting for your timezone. I did a little testing and found yesterday's date with:
TZ=EST+5 date

One may want to allow for Daylight Savings Time. In the case of Eastern US you could check the results of "date +%Z". If EDT you could then use:
TZ=EDT-20 date
or for yesterday:
TZ=EDT+4 date

Actually, it didn't matter if I use EST or EDT as long as the numerical offset was adjusted.

I didn't test for dates and times during the time change between EST and EDT (nor vice versa). I wonder what the results would be?

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
James R. Ferguson
Acclaimed Contributor

Re: Script Help

Hi Darrell:

Our European friends living around the Prime Meridian are the "lucky" ones who can use +-24 hours to exactly compute yesterday or tommorrow including the correct time.

If you look at the man pages for environ (5) you will note that offset is the value that must be added to local time to arrive at UTC (GMT). Offset takes the format hh[:mm[:ss]]
where (hh)is any value from 0 through 23. The optional minutes (mm) and seconds (ss) fields are a value from 0 through 59. The hour field is required. If offset is preceded by a -, the time zone is east of the Prime Meridian. A + preceding offset indicates that the time
one is west of the Prime Meridian.

Notice, for example that while it is now 1100 hours on February 6 in the Eastern US, you cannot produce a date *and time* exactly 24-hours ago. To affect this, the computation would need to offset 29 hours (24+5), an invalid offset.

Regards!

...JRF...
Nobody's Hero
Valued Contributor

Re: Script Help

Thanks, everyone. Some good suggestions.
UNIX IS GOOD
Darrell Allen
Honored Contributor

Re: Script Help

A retraction...

Regarding: TZ=EST+5 date

After seeing another post today, I looked back at this one and noticed Jim's last comment. So I tried it again.

I swear I tested using EST+5 yesterday before posting but now it doesn't work! So, even though I thought it worked then, it definitely does not work now.

I gotta lay off the cafeine (or maybe I need more)! My apologies.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)