Solved

Timeshifting dates in AIX...

Posted on 2004-10-04
6
2,449 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now