Solved

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

Posted on 2003-11-12
10
3,227 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
  • 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 400 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 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