How to get output of today() function as string in google sheet - spreadsheet

I want to append quote to the date value which i receive from =today()-1 function.
Expected output is eg. - "30/05/2018"

Could Achieve with below -
=CONCATENATE(CHAR(34),TO_TEXT(today()),CHAR(34))

Related

Getting: INVALID_FUNCTION_ARGUMENT: Invalid format: "" when trying to date_parse a string formatted date

Query:
SELECT date_parse(start_date, '%Y/%m/%d')
FROM sql_question_five_2 ;
date format looks like this in csv: 20210531
being read into table as string.
Have tried a few different things to get it to convert to a date YYYY-MM-DD
date_parse expects all inputs to look like the format string, if they don't it will throw an error. You can do something like this to avoid the problem:
SELECT IF(start_date = '', NULL, date_parse(start_date, '%Y/%m/%d'))
FROM sql_question_five_2
This guards against the case where the string is empty, which is the case when you get the error. If you have other strings that don't conform to the format you would have to guard against those too.
If that is the case you can use the TRY function which captures errors and returns NULL:
SELECT TRY(date_parse(start_date, '%Y/%m/%d'))
FROM sql_question_five_2
Your format string needs to match the source value. Your source doesn’t have /‘s in it so your format string shouldn’t either

Redshift query data format

one of the column has data in format as below:
column_name_a:
abcd/date=2018-01-01/part-0001-asdfasdfasdf
abcd/date=2018-01-01/part-0002-asdfasdfasdf
abcd/date=2018-01-02/part-0001-asdfasdfasdf
abcd/date=2018-01-02/part-0002-asdfasdfasdf
abcd/date=2018-01-03/part-0001-asdfasdfasdf
abcd/date=2018-01-03/part-0002-asdfasdfasdf
abcd/date=2018-01-03/part-0003-asdfasdfasdf
abcd/date=2018-01-03/part-0004-asdfasdfasdf
.....
Now I need to get file count either by day or by part number.
How do I write my query?
Adding to Nate's answer, you can use split_part multiple times to get what you require:
To get date:
select split_part(split_part('abcd/date=2018-01-01/part-0001-asdfasdfasdf','/',2),'=',2)
To get part number:
select split_part(split_part('abcd/date=2018-01-01/part-0001-asdfasdfasdf','/',3),'-',2)
Use split_part. This will still have 'date=' in the string..
date = split_part(column_name_a,'/',2)
part_number = split_part(column_name_a,'/',3)
details are here...
https://docs.aws.amazon.com/redshift/latest/dg/SPLIT_PART.html

Change month name to month number in SSIS

I have a source file which has 50 columns. One of the columns is TransDateTime and the value in it is of format 22-MAY-2017 02:31:15.00. Now before loading this source file to final destination table i want it to be converted to the format 22-05-2017 02:31:15.00 so that i can use the data type datetime for that column.
I have seen ways to convert month name to month number if the column just contains the month value like below.
http://www.techbrothersit.com/2014/11/ssis-how-to-convert-month-name-into.html
I am not sure how to work around this scenario in my case. Any solutions?
Well one solution would be to REPLACE. Simply replace "MAY" with "05" and you get the desired outcome from your sample input.
Nest 12 REPLACE functions in one expression and you will handle every possible scenario.
Use a script component. Convert the input column to your desired format like this in C#:
DateTime.Parse("22-MAY-2017 02:31:15.00").ToString("dd-MM-yyyy HH:mm:ss.ff");
For example, if your input column is MyDate and Out put column is OutPutCol then:
OutPutCol = DateTime.Parse(Row.MyDate).ToString("dd-MM-yyyy HH:mm:ss.ff");
You can check the code here.
If your destination column datatype is datetime, so you are not looking to reformat your date string. but you are looking to convert this string into date value.
You can add a Script COmponent in the dataflow task, with an output column of type DT_DBTIMESTAMP and mark TransDateTime Column as input. and use the following code: (i used VB.NET)
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Output0Buffer)
Row.OutDate = DateTime.ParseExact(Row.TransDateTime,"dd-MMM-yyyy HH:mm:ss.ff",New System.Globalization.CultureInfo("en-GB"))
End Sub
If your destination column is of type string then you have to follow the same steps but the output column should be of type DT_STR and you have to use the following code:
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Output0Buffer)
Row.OutDate = DateTime.ParseExact(Row.TransDateTime,"dd-MMM-yyyy HH:mm:ss.ff",New System.Globalization.CultureInfo("en-GB")).ToString("dd-MM-yyyy HH:mm:ss.ff")
End Sub

Extract the last element of a list for a split string

I'm trying to take a regular expression and split it by a pre-determined character, and then extract the final value of the returned list.
For example, my string may take the form:
name
WAYNE.ROONEY.226
ROSS.BARKLEY.HELLO.113
ADAM.A122
Pythonically, what I'm trying to do is:
for x in list:
my_val = x.split('.')[-1] #Return the last element of the list when split on .
e.g. desired output:
name value
WAYNE.ROONEY.226 226
ROSS.BARKLEY.HELLO.113 113
ADAM.A122 A122
Can anyone provide me any pointers in either Hive or Impala please?
If I can create this as a view, ideally, that would be perfect, but am also happy with generating actual output with it and then re-uploading to a table
Thank you!
For Hive:
select regexp_extract(NAME, '\\.([^\\.]+)$', 1) as VALUE
from WHATEVER
And pleeeease [edit] learn the power of regular expressions...

Construct table name dynamically in pentaho

I am making a pentaho transformation and i have a table input step. My requirement was to pass the table input step dynamically as a variable and this i achieved by doing :
select * from ${table_name}
and when i run the transformation, i pass in the value of
table_name.
This works.
But my new requirement is: To pass the date as a variable and then construct a table name from the date based on the month and year
So for example:If I pass in 2012-01-31, I want a sql like this:
select * from xxx_201201_v
I cannot use a substr like this:
select * from xxx_substr(${input_date} ,0,4)
So I am confused how to do this
You could use a Get Variables step so you have your date in a field. Then use steps to manipulate your strings and then pass the field to the Table Input step like this
select * from ?
Of course you should activate the option of the Table Input step to get fields from a previous step. If you have 2012-01-31 you can get 201201 using a find and replace step where you find "-" and replace it with nothing, and then cut the string so that you have the first 6 digits.