Elasticsearch query converting UTC to PST - elasticsearch

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.

Related

Format dates in response field in elastic search

My server on which the application runs (uses ES) and ES are in central american time and I am accessing it from my server which is in IST.
I want some charts and data for today(Say Jan 3) so I send from date as today 12:00 AM to to date as current date in UTC to date range query. I get accurate number of records but I want the date to be shown as todays date alone(Jan 3), It gets divided between today(Jan 3) and yesterday(Jan 2) on client side access - ideally it should only todays date on client side for all records. Kibana renders correctly. So obviously there is a way and I am missing someting
I am using date range query - passing UTC for both to and from date and timezone offset as well.
Also, I am querying on a field which is of default type Date.I have not specified any custom date formats
Can somebody pleas help me with this?

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?

Dealing with timezones in 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?

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])

Resources