Linux Server Time Zone $TZ Problem - Yesterday Date Script

I encountered a peculiar problem in a shell script that was used to find the yesterday's and tomorrow's date using the environmental variable TZ. The script that was previously written to find yesterday's date on a server that was located in EDT time zone was

YesterdayDate=`TZ="EDT+24" date`

But unfortunately the code failed to give the correct date of yesterday and instead it gave today's date. I thought of digging deep into this issue and logged in to a linux server to investigate the matter. After some long manipulations I observed something.

Unix server time zone $TZ

BST is 1 hour ahead of UTC $ YesterdayDate=`TZ="BST+23" date`

The script "EDT+24" gave only GMT/UTC time and inorder to get the correct timezone I needed to add the offset value for the particular time zone. After I made the changes the script seems to be working fine.

EDT is 4 hours behind of UTC $ YesterdayDate=`TZ="EDT+28" date`

CDT is 5 hours behind of UTC $ YesterdayDate=`TZ="CDT+29" date`

MDT is 6 hours behind of UTC $ YesterdayDate=`TZ="MDT+30" date`

PDT is 7 hours behind of UTC $ YesterdayDate=`TZ="PDT+31" date`

I'm still a bit confused as to why the $TZ is behaving so unexpectedly.

Note: I'm just a novice and not an expert in Unix or Shell Scripting. I just wanted to share my experience with timezones on linux servers.

4 comments:

eDoDe said...

The post is nice one.. The change is Done.. U can visit the blog to check that... Have a Good Day... eDoDe was here...

no name said...

nice info.......have anice day......keep in touch.....pls visit me back...THX

Get More Healthy said...

Thanks for the information..good job my friend..

Anonymous said...

This was useful for me

Post a Comment