4

I'm trying to change some old .asp files with vbs. Our database is going to be converted to store dates in UTC, but on webpages it should show dates and time in "Europe/Helsinki" timezone(

TimeZoneInfo.FindSystemTimeZoneById("FLE Standard Time")

in c#). How can I cast the UTC date I get from db query( the query is run in the .asp file as well and the result put into table) to correct date time using vbscript?

user692942
  • 16,398
  • 7
  • 76
  • 175
Margo
  • 672
  • 3
  • 13
  • 30
  • @SalmanA As long as you know the timezone offset you can use `DateAdd()` to + - hours from the passed date-time value. – user692942 Jun 02 '16 at 12:50
  • @Lankymart those are old dates and it will not always be the same amount of hours to add since we have daylight saving time. – Margo Jun 02 '16 at 13:12
  • I did point that out in my answer, how you workout what should have DST applied and what shouldn't is up to you and depends on the information you have to work with. They spoil you with .Net. – user692942 Jun 02 '16 at 13:13

1 Answers1

5

Just offset the UTC dates using DateAdd().

Const EETOffset = -2 'EET offset from UTC is -2 hours
Dim dbDateValue  'Assumed value from DB
Dim newDate
'... DB process to populate dbDateValue
newDate = DateAdd("h", EETOffset, dbDateValue)

Note: One problem with this approach is you will also have to compensate for EET and EEST (Eastern European Summer Time) manually based on the time of year. Which is also more difficult when you take into consideration some places don't use it and use EET all year round instead.
See EET – Eastern European Time (Standard Time).

Depending on the RDMS you are using you should even be able to manipulate the dates before they get to the page as part of the initial query.


Useful Links

Community
  • 1
  • 1
user692942
  • 16,398
  • 7
  • 76
  • 175
  • So there is no easy way to do this(without calculating manually if the date is sommer og winter time) just using vbscript? – Margo Jun 02 '16 at 13:19
  • 2
    @Margo I thought maybe the `System.TimeZoneInfo` could be instantiated with `CreateObject` but it doesn't look as though .Net exposes that class to COM so in short.. No there isn't. – user692942 Jun 02 '16 at 13:34