hive convert PHT time to UTC - time

select to_utc_timestamp(current_timestamp(),'IST');
is converting to utc from ist.
but,
select to_utc_timestamp(current_timestamp(),'PHT');
PHT time is not converting, it simply returning current timestamp in utc.
select current_timestamp(),to_utc_timestamp(current_timestamp(),'PHT');
| 2019-07-10 07:52:29.795 | 2019-07-10 07:52:29.795 |
returning utc only.

You need to specify the continent/capital of country:
select to_utc_timestamp(current_timestamp(),'Asia/Manila');

'PHT' timezine is not recognized because java.time.ZoneId does not contain such zone, it contains IST though. Use GMT offset notation like this:
hive> select current_timestamp(),to_utc_timestamp(current_timestamp(),'GMT+8:00');
OK
2019-07-10 23:21:24.743 2019-07-10 15:21:24.743
Time taken: 0.096 seconds, Fetched: 1 row(s)
I am not completely sure is it GMT+8:00 in Phillipines or should it be GMT-8:00, you should know better, to_utc_timestamp() will work correctly if you specify correct GMT offset. And there is no daylight saving time in Manilla hence this method should work fine.
Asia/Manila also works fine and as #F.Lazarescu mentioned this is better to use timezone identifier instead of GMT offset because daylight saving will be counted if applicable:
select current_timestamp(),to_utc_timestamp(current_timestamp(),'Asia/Manila');
OK
2019-07-11 23:09:47.257 2019-07-11 15:09:47.257
Time taken: 4.029 seconds, Fetched: 1 row(s)
Have a look at this rather useful article also: Watch out for timezones with Sqoop, Hive, Impala and Spark

Don't use time zone abbreviations as identifiers. IST could be India Standard Time, Israel Standard Time or Ireland Standard Time. (There are lots of other ambiguities.)
If by IST you meant India, then use 'Asia/Kolkata'
If by IST you meant Israel, then use 'Asia/Jerusalem'
If by IST you meant Irelant, then use 'Europe/Dublin'
Instead of PHT, use 'Asia/Manila' for the Philippines
See the list of tz database time zones on Wikipedia for the complete list.

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?

Where between in laravel not returning the date that entered in the limit?

$tasks->whereBetween('start_datetime', [$request['start_date_report'], $request['end_date_report']]);
not returning $request['end_date_report'] data.
This problem typically not related to Laravel or any framework, the problem is in the logic of your query.
The problem is probably like this:
You have a datetime column
Your data include the time part, for example you have data 2017-12-01 08:00:00 and 2017-12-02 09:00:00
Your query does not include the time part: between '2017-12-01' and '2017-12-02'
This would result only one data that is 2017-12-01 08:00:00, this is because every database engine would default the time to 00:00:00 so your query is equal to between '2017-12-01 00:00:00' and '2017-12-02 00:00:00'
Therefore, 2017-12-02 09:00:00 is greater than the upper limit of 2017-12-02 00:00:00, thus not included in the result
So, if you want to include 2017-12-02 09:00:00 in the result, you can add the end date by 1 day (without the time part of-course), or make sure you compare the date part only

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?

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

Does to_utc_timestamp take into account daylight saving?

I'm trying to convert EST datetime to UTC in a Hive query, but can't see daylight saving taken into account. Do you know how to account for daylight saving in Hive?
For example:
TO_UTC_TIMESTAMP('2014-12-31 00:00:00', 'EST') gives 2014-12-31 05:00:00 i.e. 5 hour difference
TO_UTC_TIMESTAMP('2014-06-30 00:00:00', 'EST') gives 2014-06-30 05:00:00, also 5 hour difference
I'm expecting the June query to give a 4 hour difference.
In June the East Coast observes EDT (Eastern Daylight Savings Time), but Hive doesn't understand EDT at all:
TO_UTC_TIMESTAMP('2014-12-31 00:00:00', 'EDT') gives 2014-12-31 00:00:00 i.e. no difference
Any ideas?
Thanks,
Ilmari
(Running Hadoop 1.0.3 on AWS Elastic MapReduce)
Here is an open ticket from the Hive project that address this issue.
https://issues.apache.org/jira/browse/HIVE-12194
See 2nd comment:
Ben Breakstone added a comment - 16/Oct/15 16:54
It's worth noting the daylight saving time version of US three-letter codes like "PDT" are not included in /lib/zi/ for the Oracle JDK. New identifiers like "PST8PDT" appear to work as expected.
See http://www.oracle.com/technetwork/articles/javase/alertfurtherinfo-139131.html
Perhaps as Ben Breakstone suggests new identifiers will work?

Resources