Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Timeshifting dates in AIX...

Posted on 2004-10-04
6
Medium Priority
?
2,471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

610 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