How can we match a date value like 2014-Dec-20 in unix_timestamp()? The pattern yyyy-MM-dd matches 2014-12-20 format. But yyyy-mmm-dd or yyyy-m-dd doesn't do the trick for matching the month name.
Got the answer from the hive community. "MMM" will match the three letter month code in unix_timestamp() in Hive.
eg: select request,unix_timestamp(time,'dd/MMM/yyyy:HH:mm:ss') from apachelogs;
Related
I have a table with column DATE. Date is 'dd/mm/yyyy' and I want only days. So I try with extract and return what I need, but I what using transpose for column to row.
The select statement is:
select EXTRACT (DAY FROM "DATE") DAY
from people;
Is this thing possible?
Thank you!
If you have a string, then just use the leftmost two characters:
select substr("DATE", 1, 2) as day
That said, you should not be storing dates as strings. It is wrong, wrong, wrong. You cannot use the built-in date/time functions. You cannot use inequality comparisons either. Fix your data model.
The date format doesn't matter. It is linked to your NLS local settings and this is how you see this.
To have it generic and extract DAY from the date do this:
select to_char(sysdate, 'DD') from dual;
Would return 07 since it's September 7th 2020.
I want week number from different columns of Year, Month & Day in same table of Hive QL.
IF you can give logic on SQL, that's also fine.
Concatenate the date, month and year into a proper date format and apply weekofyear().
Select weekofyear(cast(concat(year,"-",month,"-",date) as date)) from tablename.
Please note that I have used cast to convert the concatenated string into date.Howver, you might need to use different method based on your date format. Please refer to the below answer on handling string conversion to date formats.
Hive cast string to date dd-MM-yyyy
In a specific column I have grouped all the dates with timestamp sorted ASC as a string with ; seperator and that column can contain 1 - 50 date strings. From the date strings I have, i need to fetch the latest dates Min value.
Sample, (let's assume sysdaye date is 07/25/2019).
07/24/2019 12:02:44;
07/24/2019 12:03:56;
07/24/2019 10:02:44;
07/25/2019 12:02:44;
07/25/2019 12:03:56.
I am not certain the date value I wanted comes in the certain position and I know it can be done with RegEx. Can someone give me a RegEx for this or a suitable suggestion to do this any other way in Oracle SQL?
Assuming all your dates are sorted and have exactly one format, here's regex solution
select
dates,
regexp_substr(
dates,
concat(
regexp_substr(regexp_substr(dates, '(\d|\s|/|:|-)+$'), '(\d|/|:|-)+'),
'(\d|\s|/|:|-)+')
) as max_date_min_datetime
from
<table_name>
I am using sql for database connectivity. I am filtering records in database on date basis using sql query which consists of function convert(varchar(100),column name,106). I am comparing it with date having dd/MMM/yyyy format. As a result I get records of next all the dates.
Example: If I try to filter the table by 01/June/2017 then inspite of having records of that date, I get records of next all the dates. I am not able to get records of 01/June/2017.
I have used greater than or equal to expression.
It is better to convert it to this yyyymmdd number format and do the comparison as below:
select convert(int,convert(varchar(10),[your column],112))
20170529
Don't convert your dates into any format (=strings) when doing comparison. Always use the date (or datetime etc) format. That way you will be comparing the actual values, not string or numeric comparison. Here the problem is that format 106 is dd mon yyyy so it will never match your date because it's a string dd/MMM/yyyy but you will get any dates starting with 02 anyhow, for example 02/Jan/1990, because in alphabetical order that will come after your given date.
I have a table with three columns: number of ten digits, time and name.
1473522179,18:39,sukesh
1474209006,9:16,syam
1473820431,7:40,ram
How can i convert first column into date with GMT timeZone using hive and pig?
Use ToDate.Assuming your relation has fields f1,f2,f3
B = FOREACH A GENERATE ToDate(f1),f2,f3;
Hive
SELECT from_unixtime(f1),f2,f3 from A
It can be done by using from_unixtime, for example your first column date is:
to_utc_timestamp(from_unixtime(1473522179),"GMT")
2016-09-10 18:42:59.0