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' )
Related
In Informatica I use the below expression:
IIF( PARAMETER_NAME='$$CURRENT_DATE_IN_SQL_FORMAT',TO_CHAR(SYSDATE,'YYYY-MM-DD'),'PARAMETER_VALUE')
which give me the date in format 2021-11-25
But I need it me to return value as below format
TO_DATE('2021-11-25', 'YYYY-MM-DD')
Any help is much appreciated
Thanks
You can use below expression.
IIF( PARAMETER_NAME='$$CURRENT_DATE_IN_SQL_FORMAT',
'TO_DATE('|| CHR(39)||
TO_CHAR(SYSDATE,'YYYY-MM-DD')||chr(39)||','||chr(39)||'YYYY-MM-DD'||chr(39)||')',
,'PARAMETER_VALUE')
You can calculate your expected output by concatenating quote, and ||.
I have data with Date info imported in Big Query in format 2/13/2016 , 3/4/2012 etc
I want to convert it into Date format like 02-12-2016 and 03-04-2012.
I want to use a Query to create a new column and use regex for the same.
I know the regex to match the first part (2) of 2/4/2012 will be something like
^(\d{1})(/|-)
Reg ex to match the the 2nd part with / would be
(/)(\d{1})(/)
I am wondering how to use these 2 regex along with REGEXP_EXTRACT and REGEXP_REPLACE to create a new column with these dates in correct format.
It might be easiest just to convert to a DATE type column. For example:
#standardSQL
SELECT
PARSE_DATE('%m/%d/%Y', date_string) AS date
FROM (
SELECT '2/13/2016' AS date_string UNION ALL
SELECT '3/4/2012' AS date_string
);
Another option--if you want to keep the dates as strings--is to use REPLACE:
#standardSQL
SELECT
REPLACE(date_string, '/', '-') AS date
FROM (
SELECT '2/13/2016' AS date_string UNION ALL
SELECT '3/4/2012' AS date_string
);
I have a data which is being fed in the below format -
2016-006-011 04:58:22.058
This is an incorrect date/timestamp format and in order to convert this to a right one as below -
2016-06-11 04:58:22.058
I'm trying to achieve this using regex in redshift. Is there a way to remove the additional Zero(0) in the date and month portion using regex. I need something more generic and not tailed for this example alone as date will vary.
The function regexp_replace() (see documentation) should do the trick:
select
regexp_replace(
'2016-006-011 04:58:22.058' -- use your date column here instead
, '\-0([0-9]{2}\-)0([0-9]{2})' -- matches "-006-011", captures "06-" in $1, "11" in $2
, '-$1$2' -- inserts $1 and $2 to give "-06-11"
)
;
And so the result is, as required:
regexp_replace
-------------------------
2016-06-11 04:58:22.058
(1 row)
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')
Is there an existing solution to create a regular expressions dynamically out of a given date-time format pattern? The supported date-time format pattern does not matter (Joda DateTimeFormat, java.text.SimpleDateTimeFormat or others).
As a specific example, for a given date-time format like dd/MM/yyyy hh:mm, it should generate the corresponding regular expression to match the date-times within the specified formats.
I guess you have a limited alphabet that your time formats can be constructed of. That means, "HH" would always be "hours" on the 24-hour clock, "dd" always the day with leading zero, and so on.
Because of the sequential nature of a time format, you could try to tokenize a format string of "dd/mm/yyyy HH:nn" into an array ["dd", "/", "mm", "/", "yyyy", " ", "HH", ":", "nn"]. Then go ahead and form a pattern string from that array by replacing "HH" with "([01][0-9]|2[0-3])" and so on. Preconstruct these pattern atoms into a lookup table/array. All parts of your array that are not in the lookup table are literals. Escape them to according regex rules and append them to you pattern string.
EDIT: As a side effect for a regex based solution, when you put all regex "atoms" of your lookup table into parens and keep track of their order in a given format string, you would be able to use sub-matches to extract the required components from a match and feed them into a CreateDate function, thus skipping the ParseDate part altogether.
If you are looking for basic date checking, this code matches this data.
\b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}\b
10/07/2008
10.07.2008
1-01/2008
10/07/08
10.07.2008
1-01/08
Code via regexbuddy
SimpleDateFormat already does this with the parse() method.
If you need to parse multiple dates from a single string, start with a regex (even if it matches too leniently), and use parse() on all the potential matches found by the regex.
The below given js / jQuery code is for dynamically generated RegEx for the Date format only, not for DateTime (Development version not fully tested yet.)
Date Format should be in "D M Y".
E.g.
DD-MM-YY
DD-MM-YYYY
YYYY-MM-DD
YYYY-DD-MM
MM-DD-YYYY
MM-DD-YY
DD/MM/YY
DD/MM/YYYY
YYYY/MM/DD
YYYY/DD/MM
MM/DD/YYYY
MM/DD/YY
Or other formats but created with "D M Y" characters:
var dateFormat = "DD-MM-YYYY";
var order = [];
var position = {"D":dateFormat.search('D'),"M":dateFormat.search('M'),"Y":dateFormat.search('Y')};
var count = {"D":dateFormat.split("D").length - 1,"M":dateFormat.split("M").length - 1,"Y":dateFormat.split("Y").length - 1};
var seprator ='';
for(var i=0; i<dateFormat.length; i++){
if(["Y","M","D"].indexOf(dateFormat.charAt(i))<0){
seprator = dateFormat.charAt(i);
}else{
if(order.indexOf(dateFormat.charAt(i)) <0 ){
order.push(dateFormat.charAt(i));
}
}
}
var regEx = "^";
$(order).each(function(ok,ov){
regEx += '(\d{'+count[ov]+'})'+seprator;
});
regEx = regEx.substr(0,(regEx.length)-1);
regEx +="$";
var re = new RegExp(regEx);
console.log(re);
NOTE: There is no validation check for months / days
e.g. month should be in 01-12 or date should be in 01-31