Solved

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

Posted on 2003-11-12
10
3,327 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 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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