How can I convert this date :
Dec 30, 2013
in the format 'YYYY-MM-DD' in hive :
2013-12-30
I can do explode and concat to match with given format but converting Dec to 12 is problem.
The UDF is the way to go in hive or impala, but if you have an ETL defined before loading data in HDFS, suggest let the ETL carry out the date conversion. It is important to store dates in format YYYY-MM-DD in order to leverage the TO_DATE() in hive or impala
If all your date is in this format then you can write a UDF which reads that column as string,
then converts the date to a given format. Something like this:
public String convertDate(String dt2) throws ParseException{
SimpleDateFormat incommingDateFormat = new SimpleDateFormat("MMM dd, yyyy");
SimpleDateFormat convertedDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date dt = incommingDateFormat.parse(dt2);
return convertedDateFormat.format(dt);
}
Hope this helps...!!!
Related
I have really simple date as string as ISO const mytDate = '2021-10-24T16:00:00.000Z' and I want to format it like format(new Date(myDate), 'yyyy-MM-dd HH:mm:ss') but new Date() cause that it convert it to my local timezone and I do not want it. I would like to take this string date and just format it as it is.
Is there a solution ?
Cheers!
I import an Excel-spreadsheet using the following SAS-procedure.
%let datafile = 'Excel.xlsx'
%let tablename = myDB
proc import datafile = &datafile
out = &tablename
dbms = xlsx
replace
;
run;
One of the variables (date_variable) has the format DD.MM.YYYY. Therefore, I was defining a new format like this:
data &tablename;
set &tablename;
format date_variable mmddyy10.;
run;
Now, I would like to sort the table by that variable:
proc sort data = &tablename;
by date_variable;
run;
However, as the date_variable is defined as a string, I dont get the sorting right. How can I re-define the date_variable as a date?
Use the input function to convert the string-value containing a date representation to a date-value that can have a date-style format applied to it that will affect how the date-value is rendered in output and viewers.
The input function requires an informat as an argument. Check the format documentation, which includes an entry for:
DDMMYYw. Informat
Reads date values in the form ddmmyy or dd-mm-yy, where a special character, such as a hyphen (-), period (.), or slash (/), separates the day, month, and year; the year can be either 2 or 4 digits.
Example:
* string values contain date representations;
data have;
input date_from_excel $10.;
cards;
31.01.2019
01.02.2019
15.01.2019
run;
data want;
set have;
date = input(date_from_excel, ddmmyy10.); * convert to SAS date values;
format date ddmmyyd10.; * format to apply when rendering those values;
run;
* sort by SAS date values;
proc sort data=want;
by date;
run;
format date_variable mmddyy10.; does not convert a string to a date. It just sets a format for displaying that field etc.
Essentially I think what you are saying is date_variable is a string that looks like "31.01.2019". If that is the case, you will have to first convert it into a date value:
date_variable_converted = input(date_variable, DDMMYY10.);
You should be now able to sort using date_variable_converted which is a SAS date value.
As my first exploration in D3.js,there is a datefield in the csv defined as '01/12/2016'.how to convert this to a proper d3.TimeFormat ?
Your Format is DD/MM/YYYY(01/12/2016)
Use the Following d3 time Format
var parseDate = d3.time.format("%d/%m/%Y").parse;
parseDate('YOUR DATE FORMAT');
Hi I am playing around with Pig for the first time and am curious how to deal with splitting up a field into multiple other fields.
I have a bag, A, like the one below:
grunt> Dump A;
(text, text, Mon Mar 07 12:00:00 CDT 2016)
What I'd like to do is split the Date-Time field into multiple fields so that I can explore the distribution of the data set and do group bys on the Day of Week, Month, Year, etc.
I have been looking at tokenize but am unsure this meets my needs as I need/want to have field names added to the bag or create a nested bag.
Any ideas?
Assuming that the value is already of datatype datetime, then you could use the following functions to extract individual elements.Builtin function reference DateTime Functions in PIG
B = FOREACH A GENERATE f1,f2,
GetDay(f3) as f3_Day,
GetMonth(f3) as f3_Month,
GetYear(f3) as f3_Year,
GetHour(f3) as f3_Hour,
GetMinute(f3) as f3_Minute,
GetSecond(f3) as f3_Second;
If the datatype is chararray then use the ToDate() function to convert it to datetime and extract the date parts.
B = FOREACH A GENERATE f1,f2,ToDate(f3,'choose your datetime format') as f3_Date;
C = FOREACH B GENERATE f1,f2,
GetDay(f3_Date) as f3_Day,
GetMonth(f3_Date) as f3_Month,
GetYear(f3_Date) as f3_Year,
GetHour(f3_Date) as f3_Hour,
GetMinute(f3_Date) as f3_Minute,
GetSecond(f3_Date) as f3_Second;
I have Oracle database with Date column in it and I want to retrieve it from recordset using Calendar since I want to compare it with today's date which is built using Calendar.
Not really sure what you meant with retrieving the date "using Calendar", but if you are using Java, and want to read a date from database and compare it with today's date, it goes like this:
java.sql.Date dbDate = resultset.getDate("dateField");
java.util.Date date = new Date(dbDate.getTime());
Calendar calendar = Calendar.getInstance();
java.util.Date today = calendar.getTime(); // "today = new Date();" would work just as well
if (date.before(today)) {
// do something
} else if (date.after(today)) {
// do something else
}