I would like to convert the array to an array string so that this ["2016-06-02","2016-06-02"] becomes 2016-06-02| 2016-06-02
Use concat_ws(string delimiter, array<string>) function to concatenate array:
select concat_ws(',',collect_set(date)) from table;
If the date field is not string, then convert it to string: concat_ws(',',collect_set(cast(date as string)))
Related
I have a table of string data. It is essentially a csv file.
Example string: "01.10.2021 5:41:15";"255,1759949"
I need to convert datatype from string to date
Need to replace original string with date column
The simpliest way is to add and drop column:
removeColumns(
addColumns(
table("<<str1><S>><<str2><S>>","01.10.2021 5:41:15","255,1759949","01.10.2021 5:41:15","255,1759949")
,"<d><D>"
,"parseDate({str1}, 'dd.MM.yy HH:mm:ss', 'GMT+3' )"
)
,"str1"
)
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.
In hive how to convert a string to number where the number is formatted and string for hour ?
Samples :
String with formatted to integer
40.868.031 => 40868031
String to hour
0:06:52.203954 => 00:06:52
I'm trying to display a date column in grid like this: "dd-mm-yyyy". In dbf table, the date is stored in this format: "YYYY-MM-DDThh:mm:ss" in a character field.
The grid is created from this cursor:
select id,beginningDate,endDate,cnp from doc ORDER BY id desc INTO CURSOR myCursor
I wish something like this:
select id,convert(beginningDate, Datetime,"dd-mm-yyyy"),endDate,cnp from doc ORDER BY id desc INTO CURSOR myCursor
Fox doesn't have a builtin function called convert(), nor can it handle your non-standard date/time string format directly.
A quick and dirty way to convert a string foo in the given format ("YYYY-MM-DDThh:mm:ss") to a date/time value is
ctot("^" + chrtran(foo, "T", " "))
The caret marks the input as the locale-independent standard format, which differs from the input format only by having a space instead of a 'T'.
You can extract the date portion from this via the ttod() function, or simply extract only the date portion from the string and convert that:
ctod("^" + left(foo, 10))
Fox's controls - including those in a grid - normally use the configured Windows system format (assuming that set("SYSFORMATS") == "ON"); you can override this by playing with the SET DATE command.
There seems to be no mask-based date formatting option as in most other languages. dtoc() and ttoc() don't take format strings, transform() takes a format string but blithely ignores it for date values.
I am with Tamar on this subject, you should have used a datetime field instead.
Since you are storing it like this anyway, you can 'convert' to datetime using the built-in cast function (or ttod(ctot()) in versions older than VFP9 - in either case you don't need to remove T character):
select id, ;
Cast(Cast("^"+beginningDate as datetime) as date) as beginningDate, ;
endDate,cnp ;
from doc ;
ORDER BY id desc ;
INTO CURSOR myCursor ;
nofilter
In grid or any other textbox control, you can control its display style using DateFormat property. ie:
* assuming it is Columns(2). 11 is DMY
thisform.myGrid.Columns(2).SetAll('DateFormat', 11)
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;