LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-10-2010, 06:44 PM   #1
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Rep: Reputation: 15
Finding the Day of the Week in different timezones


I am using the following to find the Day of the Week on my server which is in UTC.

Code:
DAY=$(date --date="yesterday" +'%A')
But say if I want to find the Day of the Week in another timezone, how would one go about it. I had a look at date --help but could not find any timezone related switches so am not sure if this is possible using this method.

Update:

This appears to work but is this the only way?

Code:
DAY=$(TZ=EST date --date="yesterday" +'%A')
Thanks & Regards,

Last edited by hattori.hanzo; 11-10-2010 at 07:17 PM. Reason: update
 
Old 11-10-2010, 07:17 PM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
I ran this bash script:
Code:
#!/bin/bash

where=-12

while [[ $where -lt 13 ]]
do
  if [[ $where -ge 0 ]]
  then
    where=+$where
  fi
  export TZ=UTC$where
  DATE=$(date)
  DAY=$(date --date=yesterday +'%A')
  echo $TZ $DATE $DAY
  where=$(($where+1))
done
and got this output:
Code:
UTC-12 Thu Nov 11 13:16:10 UTC 2010 Wednesday
UTC-11 Thu Nov 11 12:16:10 UTC 2010 Wednesday
UTC-10 Thu Nov 11 11:16:10 UTC 2010 Wednesday
UTC-9 Thu Nov 11 10:16:10 UTC 2010 Wednesday
UTC-8 Thu Nov 11 09:16:10 UTC 2010 Wednesday
UTC-7 Thu Nov 11 08:16:10 UTC 2010 Wednesday
UTC-6 Thu Nov 11 07:16:10 UTC 2010 Wednesday
UTC-5 Thu Nov 11 06:16:10 UTC 2010 Wednesday
UTC-4 Thu Nov 11 05:16:10 UTC 2010 Wednesday
UTC-3 Thu Nov 11 04:16:10 UTC 2010 Wednesday
UTC-2 Thu Nov 11 03:16:10 UTC 2010 Wednesday
UTC-1 Thu Nov 11 02:16:10 UTC 2010 Wednesday
UTC+0 Thu Nov 11 01:16:10 UTC 2010 Wednesday
UTC+1 Thu Nov 11 00:16:10 UTC 2010 Wednesday
UTC+2 Wed Nov 10 23:16:10 UTC 2010 Tuesday
UTC+3 Wed Nov 10 22:16:10 UTC 2010 Tuesday
UTC+4 Wed Nov 10 21:16:10 UTC 2010 Tuesday
UTC+5 Wed Nov 10 20:16:10 UTC 2010 Tuesday
UTC+6 Wed Nov 10 19:16:10 UTC 2010 Tuesday
UTC+7 Wed Nov 10 18:16:10 UTC 2010 Tuesday
UTC+8 Wed Nov 10 17:16:10 UTC 2010 Tuesday
UTC+9 Wed Nov 10 16:16:10 UTC 2010 Tuesday
UTC+10 Wed Nov 10 15:16:10 UTC 2010 Tuesday
UTC+11 Wed Nov 10 14:16:10 UTC 2010 Tuesday
UTC+12 Wed Nov 10 13:16:10 UTC 2010 Tuesday
Hope this helps.
 
1 members found this post helpful.
Old 11-10-2010, 07:23 PM   #3
hattori.hanzo
Member
 
Registered: Aug 2006
Posts: 168

Original Poster
Rep: Reputation: 15
Thanks wje_lq. I posted an update at the same time you posted a response. :-)

The bash script will be great to find out the Day within a 24 hour period. Appreciate it.

Thanks & regards,
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cron job: day of month / day of week conflict? geekpie Linux - General 2 10-21-2009 03:56 AM
LQ-er of the day/week/month/year? alan_ri LQ Suggestions & Feedback 0 01-24-2009 05:11 PM
Findin The Day Of The Week D-KNUCKLES Linux - General 1 10-21-2007 11:46 AM
Getting Day of Week - Java - SQL Date MRMadhav Programming 4 04-03-2006 12:01 PM
Schedule by day of the week stand Linux - General 1 08-30-2004 11:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration