Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBScript needed (subtract 5 hours or convert EST to GMT)

Posted on 2003-11-12
10
Medium Priority
?
3,496 Views
Last Modified: 2007-12-19
URGENTLY NEEDED

I'm needing to convert the time from EST to GMT and can't see any obvious function / syntax.  Since EST is GMT - 5, I need simply to subtract 5 hours from the current time.

Either that or a function to directly convert timezones (such as EST to GMT in my case)
0
Comment
Question by:tma050898
[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
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9735255
Just do this:

timGMT = DateAdd("h",-5,Now())
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 1600 total points
ID: 9735298
To be a little more elegant:

function  convertTime()
      timGMT = DateAdd("h",-5,Now())
      convertTime = FormatDateTime(timGMT,3)
end function


FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9735326
0
Industry Leaders: 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!

 
LVL 3

Author Comment

by:tma050898
ID: 9735463
Thanks! DateAdd was what I was missing. Unfortunately, I'm doing this for RSS reasons and FormatDateTime doesn't do what you need for RSS since it wants an RFC822 format date (email). So, here's the code to format the date into what the RSS output requires:

dim sRfc822Date
dim dtPubDate
dim sDay
dim sHour
dim sMinute
dim sSecond
dtPubDate = Now()

if Day(dtPubDate) < 10 then
      sDay = "0" & Day(dtPubDate)
else
      sDay = Day(dtPubDate)
end if

if Hour(dtPubDate) < 10 then
      sHour = "0" & Hour(dtPubDate)
else
      sHour = Hour(dtPubDate)
end if

if Minute(dtPubDate) < 10 then
      sMinute = "0" & Minute(dtPubDate)
else
      sMinute = Minute(dtPubDate)
end if

if Second(dtPubDate) < 10 then
      sSecond = "0" & Second(dtPubDate)
else
      sSecond = Second(dtPubDate)
end if

'Tue, 04 Nov 2003 05:00:00 GMT
sRfc822Date = WeekdayName(Weekday(dtPubDate), True) & ", " & sDay & " " &
MonthName(Month(dtPubDate), True) & " " & Year(dtPubDate) & " " & sHour &
":" & sMinute & ":" & sSecond & " GMT"

Yuck!!!

But it works...
0
 
LVL 29

Assisted Solution

by:Göran Andersson
Göran Andersson earned 400 total points
ID: 9735710
Let me at least simplify that a bit for you:

dim sRfc822Date
dim dtPubDate
dim sDay
dim sHour
dim sMinute
dim sSecond
dtPubDate = Now()

sDay = Right("0" & Day(dtPubDate),2)
sHour = Right("0" & Hour(dtPubDate),2)
sMinute = Right("0" & Minute(dtPubDate),2)
sSecond = Right("0" & Second(dtPubDate),2)

'Tue, 04 Nov 2003 05:00:00 GMT
sRfc822Date = WeekdayName(Weekday(dtPubDate), True) & ", " & sDay & " " &
MonthName(Month(dtPubDate), True) & " " & Year(dtPubDate) & " " & sHour &
":" & sMinute & ":" & sSecond & " GMT"
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9735767
I wonder if you couldn't do that via a combination of my function and use of the appropriate LCID code?

FtB
0
 
LVL 3

Author Comment

by:tma050898
ID: 9735787
Not sure, but this falls under the category of "it works, ship it" :) Seriously, being a C++ dev, this vb stuff is just something I needed to get to work very quickly for my site and you guys got me there. Thanks much!!
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9735800
Glad to have helped.

Please be sure to close out the question.

FtB
0
 

Expert Comment

by:PaschalNee
ID: 9739797
OK you have got a solution but you need to be aware of two things
- GMT is not always EST+5 as GMT does not use daylight saving time (i.e. one hour movement forward/backward in autumn/spring)
- Even BST (British Summer Time) does not always match EST+5 as there is a week in spring when the clocks move the hour a week apart.

If you are OK with this then I guess the simple +5 will do for you.  Otherwise you might be better using a 3rd party component or LCID mentioned above
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 9740701
To clarify: The locale id only affects the date format (and other formats), it does not affect daylight savings time.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 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