Dealing with timezones in vbscript - vbscript

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?

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
Format current date and time
How to format a datetime with minimal separators and timezone in VBScript?

Related

Easiest way to access .NET TimezoneInfo from Asp classic page [duplicate]

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?
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
Format current date and time
How to format a datetime with minimal separators and timezone in VBScript?

Elasticsearch query converting UTC to PST

I am running a date_histogram Elasticsearch query based on a particular time stamp range. I would like to convert the output from UTC to PST. I am running it from now to the previous 7 days ("gte": "now-7d/d"). What do I need to add to convert the output from UTC to PST which is a difference of 8 hours? I researched using the "time_zone" function but I thought that was converting a particular time to UTC ("time_zone": "+01:00").
I don't think there is any easy way (if any) to change the contents of key_as_string field in aggregation result. But, you can very well convert key field which has epoch to PST date in your application.
I hope this is useful.

Unix Shell Script Time Zone BST Or GMT

This is what i'm trying to do:
I want to create a simple shell script that checks the current timezone in the UK.
i.e. BST or GMT.
I only can display the time for the current timezone the UK is in. i.e. UK is in GMT right now and I can only display that time. [TZ=GMT date]
Please note: I do not wish to permanently modify the UNIX time zone on the server (currently CET)
Based on that I need to do some calculations (which I'm fine with)
I have already searched and I cannot find anything specific to this problem. Thank you for your help
To get the date for a particular timezone, you can do:
TZ=GMT date
(Or date +%s if you want epoch format, which is also TZ independent, but altogether friendlier for calculations. ).
For what it is now, relative time I think it's as simple as:
TZ=Europe/London date
Which I think should cause your system to report BST/GMT appropriately.
If you want it to specifically report the offset, you can use the %z format specifier:
TZ=Europe/London date +"%Y%m%d %H:%M:%S %z"

Convert Unix Timestamp - Spotfire Analyst

I'm importing SQL data into Spotfire Analyst. All of the date and time fields are in the form of a Unix timestamp. What's the best way to convert this into an actual date format that I can manipulate in Spotfire?
Utilizing a calculated column you can calculate the datetime based on the UNIX epoch.
We simply add our seconds to the DateTime of the UNIX epoch (JAN 01 1970 00:00:00 UTC) to get the result. Below is an example of the UNIX time when I started writing this post.
DateAdd("second",1429733486,DateTime(1970,1,1,0,0,0,0))
The below is what should work for you:
DateAdd("second",[UNIX_TIMESTAMP_COLUMN],DateTime(1970,1,1,0,0,0,0))
Keep in mind these dates produced will be in the UTC timezone as per the JAN 1 1970 epoch. If you need them in your local time zone you may have to adjust accordingly with further DateAdd functions adding/subtracting time as per current conversions. Also, if you observe daylight savings time you may need to add some extra case logic to handle that as well.
Please let me know if you have any questions or need further clarification.
In 7.0 and later you can use
FromEpohTimeSeconds([UNIXDATE])
or
FromEpohTimeMilliseconds([UNIXDATE])

How do I format a datetime on sqlite with timezone?

for example I have this date jan 5, 2010 14:00 wednesday gmt-8
how do I implement this so I can save it with timezone?,
I can save this using nsformatter with yyyy-MM-dd hh:mm
and saves as
2010-01-05 14:00
but how about w/ timezone?
(it should be saved in datetime format.. not text format)
You can use [format setDateFormat:#"yyyy-MM-dd hh:mm a"] for timezone it will give output like this "2010-01-05 02:00 PM"
or
[format setDateFormat:#"MMM dd, yyyy hh:mm a"]
Put the timezone in another column and you won't break the limited existing date functionality of SQLLITE. Its really easy to add columns to sqllite with an alter table statement. Android SQLite Database, WHY drop table and recreate on upgrade
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.

Resources