Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell script for manipulating the current date

Status
Not open for further replies.

fgg123

IS-IT--Management
Mar 7, 2003
6
0
0
US
Looking for a simple UNIX shell script (not java) that
if executed would do the following:

Give you the date of yesterday (today), for example;

$ date

Thu Jun 19 12:48:21 EDT 2003

$ yesterday

Wed Jun 18 12:48:22 EDT 2003

Also, the command yesterday, will take into consideration, months with 30, 31 or 28/29 days (leap year).

Also; if anyone has a script that can convert UTC Time to EDT Time.


Thanks,
fgg123
 
I don't know for sure, but if you do a search out here for 'caljd.sh', that script may help you. I am not sure if it will do that, but it may be worth looking at...
 
Try setting your TZ (Timezone) varable in a script - this doesn't affect the system time just within your script. Keep the old value so you can reset it after you've messed with it. For some reason you need to add 24 to TZ to go back 24 hours and subtract 24 to go ahead 24 hours!

#echo $TZ;date
BST
Thursday June 19 18:49:33 BST 2003
#OLD_TZ=$TZ
#TZ=$TZ+24
#date
Wednesday June 18 18:49:41 BST 2003
#TZ=$OLD_TZ
#date
Thursday June 19 18:49:45 BST 2003

Alternatively to cover all the bases and your UTC conversion try downloading gawk from sunfreeware.com. Thei is the GNU awk package and has the systime() function which returns UTC time and strftime(format,UTCtime) to display time in date like format. Should be fairly easy to write a simple gawk script to get the date and perform maths on it before converting it back to date format.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top