INFORMATICA - Date format conversion - informatica

Hello guys i have a date format of 12/05/2015 i.e., dd/mm/yyyy . I need to convert this as 05/12/2015 i.e., mm/dd/yyyy . Can any one give me a solution .

Because function TO_DATE by default expects the date as a char value to be in the form 'MM/DD/YYYY', you need to specify you're handing it in as 'DD/MM/YYYY'. Then you want the final output to be a string (presumably) in format 'MM/DD/YYYY', so for that you need the function TO_CHAR. So you have to jump that hurdle, too. The final statement for your example, then, looks like this:
TO_CHAR(TO_DATE('12/05/2015', 'DD/MM/YYYY'), 'MM/DD/YYYY')
The output will be '05/12/2015'.

Use the function TO_DATE
TO_DATE(Column_name, 'mm/dd/yyyy')

In informatica Help file, There is a chapter called "functions". In that check TO_DATE function.
TO_DATE( string [, format] )
String ---- Must be a string datatype. Passes the values that you want to convert to dates. You can enter any valid transformation expression.
format ---- Enter a valid TO_DATE format string. The format string must match the parts of the string argument. For example, if you pass the string '20150515', you must use the format string 'YYYYMMDD'.

v_PORT(DataType-DateTime)-TO_DATE(TO_CHAR(INPUTPORT),'DD/MM/YYYY')
o_PORT(String)--TO_CHAR(v_PORT,'MM/DD/YYYY')
It will work.

Use the below command, this will give you the value as per you requirement
TO_CHAR(TO_DATE(Column, 'DD/MM/YYYY'), 'MM/DD/YYYY')

Related

Extract Specific Parameter value using Regex Postgresql

Given input string as
'PARAM_1=TRUE,THRESHOLDLIST=kWh,2000,Gallons,1000,litre,3000,PARAM_2=TRUE,PARAM_3=abc,123,kWh,800,Gallons,500'
and unit_param = 'Gallons'
I need to extract value of unit_param (Gallons) which is 1000 using postgresql regex functions.
As of now, I have a function that first extracts value for THRESHOLDLIST which is "kWh,2000,Gallons,1000,litre,3000", then splits and loops over the array to get the value.
Can I get this efficiently using regex.
SELECT substring('PARAM_1=TRUE,THRESHOLDLIST=kWh,2000,Gallons,1000,litre,3000,PARAM_2=TRUE,PARAM_3=abc,123,xyz' FROM '%THRESHOLDLIST=#".........#",%' FOR '#')
Use substring() with the target input grouped:
substring(myCol, 'THRESHOLDLIST=[^=]*Gallons,([0-9]+)')
The expression [^=]* means “characters that are not =”, so it won’t match Gallons within another parameter.
select
Substring('PARAM_1=TRUE,THRESHOLDLIST=kWh,2000,Gallons,1000,litre,3000,PARAM_2=TRUE,PARAM_3=abc,123,xyz' from 'Gallons,\d*');
returns Gallons,1000

SAS date convert from numeric to character

I have a SAS variable(a table column) which has a Number data type and a format YYMMDD10.
It has a value like :04/20/2019
I want to convert it to a string like:20190420.
So I do:
new_date= Put( trim(orig_date), mmddyy10.);
I get:The format $MMDDYY was not found or could not be loaded.
Your main mistake is adding the unneeded TRIM() function.
You cannot use TRIM() function on a numeric variable. Well you can, but that just means SAS will automatically convert the number into a string using the BEST12. format. Once you have converted the data to a character string then you can no longer use the numeric MMDDYY format with the value. So SAS assumes you just left the $ off the front of your character format name. However it can't find such a character format so you get the error message.
To make sure the result has slash instead of some other delimiter you can use the MMDDYYS format.
new_date= Put( orig_date , mmddyys10.);

Informatica date format

I convert string to date format in informatica using expression transformation
TO_DATE(input_field_string,'MM/DD/YYYY HH:MI:SS '). And I want to round off the MM/DD/YYYY/ HH:MI. how do I do this using expression transformation. For example my data is 10/10/2015 10:05:09. I want to convert this to 10/10/2015 10:00 using expression.
Feed the result of your TO_DATE expression (lets call this v_Date) in a TO_CHAR function i.e. TO_CHAR (v_Date, 'MM/DD/YYYY HH24:MI' )

Data validation with RegEx on time-formatted cell

I need to validate time entered in a cell. But the cell HAS to be in date format because I will need it later to extract hours and minutes.
My RegEx will check perfectly if the cell format is plain text, but if I set it to "time" or "date" or "hh:MM", I get an error in the Spreadsheet : "Parameter 1 expects text, but 0.52154 is number type and can't be forced to text type" (approximate translation from French, sorry).
My formula :
=REGEXMATCH(F5,"([0-1][0-9]:[0-5][0-9]:[0-5][0-9])?([0-9]:[0-5][0-9]:[0-5][0-9])?([0-1][0-9]:[0-5][0-9])?([0-9]:[0-5][0-9])?")
Is there a workaround ?
You could convert number to text with formula:
=REGEXMATCH(TEXT(F5,"hh:mm:ss"),regex)
hh:mm:ss converts the number into proper sting that mimics time format.
to make sure, that entered time is in number format, you should also use ISNUMBER function:
=and(ISNUMBER(F5),REGEXMATCH(TEXT(F5,"hh:mm:ss"),regex)
will return false if text was entered.
The value reads:
Function REGEXMATCH parameter 1 expects text values. But '123' is a number and cannot be coerced to a text.
You get an error because a regex cannot be applied to values other than text. Cast the value to text and use the REGEXMATCH:
=REGEXMATCH(TEXT(F5,""),"([0-1][0-9]:[0-5][0-9]:[0-5][0-9])?([0-9]:[0-5][0-9]:[0-5][0-9])?([0-1][0-9]:[0-5][0-9])?([0-9]:[0-5][0-9])?")
^^^^^^^^^^^
Searching and testing again, I came across a variation of the =TEXT(A1,"pattern") formula : = TO_TEXT()
My final formula :
=REGEXMATCH(TO_TEXT(E20);"([0-1][0-9]:[0-5][0-9]:[0-5][0-9])|([0-9]:[0-5][0-9]:[0-5][0-9])|([0-1][0-9]:[0-5][0-9])|([0-9]:[0-5][0-9])")
I must dig a little bit to understand the difference between TO_TEXT() and TEXT()...
The issue was definitely the way you have to format the pattern parameter of the function. If something like 12h45 was entered, the =TEXT(E20;"hh:mm:ss") pattern would return 00:00:00, and the regex would be evaluated as TRUE.

how to import informats (comma separated values) into sas

I have a data with commas in tab file and I have imported it the values were imported into sas as a char datatype with a comma values.
like 23,1 53,2
I want to now convert these into numeric with either . or comma how do i do it?
if I use
want=input(have,comma.);
informat want comma.;
format want comma.;
I get missing values., !
You can use the NUMXw.d informat to input numbers with commas as the decimal separator.
want = input(have,NUM4.1);
or just use that on the initial input statement and you don't have to convert it.
NUMXw.d also is a format, so you can use it to display the variable with a comma if that's how you are more comfortable viewing decimals.
You can use a TRANWRD function to replace the comma with a period, then wrap this within an INPUT function to convert the new character value to numeric.
F2 = INPUT(TRANWRD(F1,',','.'),4.1);