Solved

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

Posted on 2003-11-12
10
3,098 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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/…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now