Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-11-12
10
Medium Priority
?
3,565 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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 video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2

772 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