Convert into am / pm in Impala - cloudera

Like in a similar query on this forum I need, but I need it to work in Impala:
In a workaround my colleague and myself attempted the following:
-- combine start date and time into a datetime
-- impala can't handle am/pm so need to look for pm indicator and add 12 hours
-- and then subtract 12 hours if it's 12:xx am or pm
================
t1.appt_time,
hours_add(
to_timestamp(concat(to_date(t1.appt_date),' ',t1.appt_time),'yyyy-MM-dd H:mm'),
12*decode(lower(strright(t1.appt_time,2)),"pm",1,0) -
12*decode(strleft(t1.appt_time,2),'12',1,0)
) as appt_datetime,
t1. ...
=========
Has anybody an easier and more elegant approach ?

Your workaround is valid, Impala does currently support AM/PM formatting for dates. There are a few open issues related
https://issues.apache.org/jira/browse/IMPALA-3381
https://issues.apache.org/jira/browse/IMPALA-5237
https://issues.apache.org/jira/browse/IMPALA-2262

Related

display a firebase timestamp in relative format using moment & react

I'm trying to display a timestamp from firebase in a relative format.
Within my firebase collection I have:
author (string): lechnerio
comment (string): Test Comment is here!
createdAt (timestamp): 22 November 2022 at 13:47:06 UTC+1
and I'd like to display the timestamp in a realtive way, e.g.: 31 minutes ago
{author} schreibt am
{moment(new Date(createdAt.nanoseconds), "YYYYMMDD").fromNow()}:
{comment}
What I'm getting back with the exact same values from above:
lechnerio schreibt am 53 years ago:
Test comment is here!
when just using new Date(createdAt) instead an invalid Date get's returned. Any suggestions on how to fix this issue. Thanks a lot in advance!
I found an answer to my issue.
{moment(createdAt.seconds * 1000).fromNow()}
In addition to the issue I was also struggling to convert english localisation to german, so "5 minutes ago" are supposed to be "vor 5 Minuten".
import moment from 'moment'
import localization from 'moment/locale/de'
moment.updateLocale("de", localization)
{moment(createdAt.seconds * 1000).fromNow()}

UTC time wrong in SQLite

My Centos 7.6 server is physically located in Germany but is configured so that it presents me (in London) with the correct local time and UTC time.
$ date
Tue Jul 16 08:31:51 BST 2019
$ date -u
Tue Jul 16 07:31:55 UTC 2019
But inside an SQLite database, things aren't right.
$ !sql
sqlite3 apollo.db
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select datetime('now');
2019-07-16 07:32:48
sqlite> select datetime('now', 'localtime');
2019-07-16 08:32:53
sqlite> select datetime('now', 'utc');
2019-07-16 06:32:58
It's displaying the local time correctly, but UTC is an hour out. Is there a config setting I can tweak to fix this?
Update: Ok. Having read the documentation a bit more carefully, it seems I was misunderstanding and this behaviour is a) correct and b) expected. select datetime('now') is the correct way to get UTC time. So now I'm just a bit confused as to what select datetime('now', 'utc') is doing (probably nothing useful).
Update: Ok. Having read the documentation a bit more carefully, it seems I was misunderstanding and this behaviour is a) correct and b) expected. select datetime('now') is the correct way to get UTC time. So now I'm just a bit confused as to what select datetime('now', 'utc') is doing (probably nothing useful).
The last paragraph before the examples explains by saying :-
The "utc" modifier is the opposite of "localtime".
"utc" assumes that the string to its left is in the local timezone and adjusts that string to be in UTC.
If the prior string is not in localtime, then the result of "utc" is undefined.
SQL As Understood By SQLite - Date And Time Functions

BlueSky Statistics - String to date [time] issues

Trying to convert time as a string to a time variable.
Use Date/Dates/Convert String to Date...... for format I use %H:%M:%S....
Here is the syntax from the GUI
[Convert String Variables to Date]
BSkystrptime (varNames = c('Time'),dateFormat = "%H:%M:%S",prefixOrSuffix = "prefix",prefixOrSuffixValue = "Con_",data = "Dataset2")
BSkyLoadRefreshDataframe(dframe=Dataset2,load.dataframe=TRUE)
A screen shot of result is attached....
Compare variables Time [string] to Con_Time [date/time]
The hours are 2 hours out [wrong!] - the Minutes and Seconds are correct.
What am I doing wrong here?
Screen Shot
I believe you are running into a known issue with a prior release of BlueSky Statistics. This issue is fixed with the current stable release available on the download page.
The reason for this was although the time is converted correctly into the local time zone, BlueSky Statistics was reading the time zone in the local time zone and converting it to UTC.
You are probably +2 hours ahead of UTC, so you are seeing the time move 2 hrs back. Give us a couple of days to post a patch.
You can also confirm this by writing and executing the following syntax in the syntax window
Dataset2$Con_Time

splunk mysearchbar.timerange.val() datetime to UTC

I am using Splunk 6.2.X along with Django bindings to create a Splunk app.
To get access to the earliest/latest dates from the timerange picker, am using the following in my JS.
mysearchbar.timerange.val()
Am getting back a map where the values are in epoch format:
Object {earliest_time: 1440122400, latest_time: 1440124200}
When I convert them using moment using the following, I get different datetime than expected:
> moment.unix('1440122400').utc().toString()
"Fri Aug 21 2015 02:00:00 GMT+0000"
However, the time does not correspond to the values that have been selected on the time range picker i.e. 08/20/2015 22:00:00.000
Am not sure what the difference is getting caused by? Am sure tht the timezone is not the factor as the time difference is erratically not equivalent to derive using simple timezone add/subtract.
I was wondering if this behaviour can be explained as to how to get the Splunk epoch datetime to UTC would be helpful.
I was able to get rid of the timezone issue by performing the following:
Setting the timezone of the Splunk engine to UTC in props.conf as follows:
TZ = GMT
Setting up the CentOS (the server hosting Splunk) to UTC
Hope this helps anyone else who stumbles upon similar issues.
Thanks.

RSpec tests fail because date in SQLite is one day ahead than the system date

I have a test that checks to see if an item was shipped today.
let(:todays_date) {I18n.l(Date.today, format: '%m/%d/%Y')}
expect(order.shipped_date.strftime("%m/%d/%Y")).to eq(todays_date)
This test fails with the following error:
Failure/Error: expect(order.shipped_date.strftime("%m/%d/%Y")).to eq(todays_date)
expected: "10/14/2014"
got: "10/15/2014"
When I check the date in SQLite is one day ahead than the system date.
sqlite> select date('now');
2014-10-15
sqlite> .exit
u2#u2-VirtualBox:~/tools/$ date
Tue Oct 14 20:13:03 EDT 2014
I appreciate any help you can provide.
Thanks!
The documentation says:
Universal Coordinated Time (UTC) is used.
To get the time in the local time zone, use the localtime modifier:
select date('now', 'localtime');
Thanks to #CL, I resolved this. I now select all dates in UTC so that they compare.
let(:todays_date) {I18n.l(Time.now.utc, format: '%m/%d/%Y')}

Resources