Solved

Timeshifting dates in AIX...

Posted on 2004-10-04
6
2,459 Views
Last Modified: 2013-12-26

I wrote this little script that is supposed to return the date 7 days ago from the current date and time but for some reason, it ignores the timezone and only returns the time in GMT... what am I doing wrong???

timezone=`date +%Z`
echo $timezone
lastweek=`TZ=$timezone+168 date +"%Y-%m-%d-%H.%M.%S"`
echo Last Week: $lastweek

output looks like this:

EDT
Last Week: 2004-09-27-13.02.25

(The time should be 9:02 a.m.)

-- Bubba
0
Comment
Question by:bganoush
  • 4
  • 2
6 Comments
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 12217291
If the time from seven days ago should be exactly the same as the time now

then , use the current time

To get the current time, use date command




0
 

Author Comment

by:bganoush
ID: 12218285

When did I say I want to get the time for seven days ago????  I want to get the DATE for seven days ago...

If you were familiar with dates and times, you would know that the date seven days before say... 11:00 p.m. on the 8th is 11:00 p.m. on the 1st... but when the date is taken from GMT, seven days before 11:00 p.m. on the 8th becomes 3:00 a.m. on the 2nd... The 2nd is NOT seven days before the 8th... If I do as you say, by getting the current time, I have the exact same problem... because 11:00 p.m. (current time) on the 2nd is exactly 6 days before 11:00 p.m. on the 8th. and please don't suggest that I just subtract 1 from the date...

What I am trying to get is the first case without any GMT conversions...

-- Bubba
0
 

Author Comment

by:bganoush
ID: 12219017
Ok,

I solved it using this code...

edt=`date +%H`
if [ $cmt -lt $edt ]; then
   cmt=`expr $cmt + 24`
fi
timediff=`expr $cmt - $edt`
echo $timediff
timezone=`expr $timediff + 168`
lastweek=`TZ=+$timediff date +"%Y-%m-%d-%H.%M.%S"`
echo Last Week: $lastweek

The way it works is that I calculate the time offset by getting the CMT hour and the EDT (my default time zone) hour and then I subtract the two. The only exception is when the CMT bumps over midnight when I need to add 24 to the CMT so that my subtraction is not negative and so that the result makes sense.  Then when I get the date, I add that offset to the offset for a week's worth of hours and then I sit back and listen to the fat lady sing!

Who wants the points?

-- Bubba
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:bganoush
ID: 12219410

I missed copying one line at the beginning:

cmt=`date -u +%H`
edt=`date +%H`
if [ $cmt -lt $edt ]; then
   cmt=`expr $cmt + 24`
fi
timediff=`expr $cmt - $edt`
echo $timediff
timezone=`expr $timediff + 168`
lastweek=`TZ=+$timediff date +"%Y-%m-%d-%H.%M.%S"`
echo Last Week: $lastweek


0
 
LVL 9

Accepted Solution

by:
HamdyHassan earned 125 total points
ID: 12221510
good work, ask for refund
0
 

Author Comment

by:bganoush
ID: 12225813

Nah... I don't do refunds!

-- Bubba
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Is it possible to combine several text files into one big one? (redhat v5 enterprise) 4 102
Whole sheet autoscrub still needed 19 51
twoTwo  challenge 35 107
MaxSpan challenge 9 105
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question