How to convert particular string to date in Talend - talend

In talend
Oct 21 - Oct 27 (2019)
is there any way to convert above text to date format, I only want 21 oct 2019 as 21/10/2019 format

Yes, it is not simple, as you have two dates on one field only, with Year appearing only once.
You can achieve this with tMap_1 --> tNormalize --> tMap_2
In tMap_1 you will have to separate "MMM-dd" from "YYYY", which appears at the end of your string. Use split method on your input field :
myFlow.myDateField.split("\\(")[0] will give you the part with `Oct 21 - Oct 27`
myFlow.myDateField.split("\\(")[1] will give you the part with the year.
Use StringHandling.LEFT to get the year only, without the closing parenthesis.
Use StringHandling.TRIM to get rid of extra spaces.
Then you will have two fields in the output.
You can then use tNormalize (normalize on "-") to put the year in front of every MMM/dd field.
In the output you'll have two rows and two columns :
"Oct 21|2019"
"Oct 27|2019"
In the final tMap , concatenate your two input fields as you wish, and use TalendDate.parseDateLocale to parse your date. (TalendDate.parseDate won't work as you have "Oct", which requires parseDateLocale method to work).

Related

Convert a dates from Tweet hydrator to standard date format in Google Sheets mm/dd/yyyy

I have a large dataset (close to 80,000) of tweets dated like this:
Wed Oct 05 01:20:53 +0000 2016
What script can I run to convert the dates in Google Sheets to the simple mm/dd/yyyy form?
In this case, it should be: 10/05/2016
Thanks!
If the format of the date is you mentioned is consistent, you can use the below formula (assuming the date is in cell A1)
=DATEVALUE(RIGHT(A1,4) & MID(A1,5,3) & MID(A1,9,2))
This will extract the Datevalue from the string and then you can format it to look in the mm/dd/yyyy format
Try
=arrayformula(if(A1:A="",,1*(regexextract(A1,"\d{2}")&"/"&regexextract(A1,"\D+ (\D+) ")&"/"&regexextract(A1,".* (\d+)"))))
or (with hours/minutes/seconds)
=arrayformula(if(A1:A="",,1*(regexextract(A1,"\d{2}")&"/"&regexextract(A1,"\D+ (\D+) ")&"/"&regexextract(A1,".* (\d+)"))+regexextract(A1,"\d{2}:\d{2}:\d{2}")))
and define the appropriate format
Another solution
=index(ifna(Text(1&RegexExtract(A:A,".*?\s(.*?)\s"),"MM")&"/"&RegexExtract(A:A,"\d{2}")&"/"&RegexExtract(A:A,".*\s(.*)")))
Or
=index(text(regexreplace(regexreplace(A:A,"\+0000\s",),"(.*)(\d+:\d+:\d+)\s(.*)","$1$3 $2"),"mm/dd/yyyy"))
Or
=index(text(regexreplace(A:A,"(.*\s)(\d+:.*)\+.*\s(.*)","$1$3 $2"),"mm/dd/yyyy"))

CakePHP - Date::i18nFormat() capitalization

I'm using Date::i18nFormat to display dates using the desired locale.
This is an example: $post->date->i18nFormat("dd 'of' MMMM"). This Outputs: 19 of june.
I would like to capitalize the first letter of the month, so it would output instead: 19 of June.
is it possible?
Thank you

conversion issue while putting transformer to read string having date values

I have the two fields
November 14 2019 10:35:24 AM and November 14 2019 as string from file
I want to convert in datstage to these fields as
11/14/2019 10:35:24AM and 20191114 respectively
Please note: after month there is one space between November and 14 and two spaces between 14 and 2019
and in output 11/14/2019 and time there is two spaces
As the input is a string and it seems you want again a string as a result string manipulation functions in a Transformer stage are always an option.
Alternatively you could also try to use the String_to_Timestamp and STRING_TO_DATE function on the same page
You will find valid format options here

Converting String to Date using T-map with Talend Open Studio

I'm having trouble converting a couple of sting fields to date with Talend Open Studio. All date fields are coming to me via csv in the format "MM/dd/yyyy hh:mm:ss aa" For example "03/20/2018 2:40:03 PM"
Many date fields are fine, and conversion with the t-map component and the talend.date (parse date) is working as it should. The problem occurs in two fields where many almost all of the dates are coming in as "12/30/1899 00:00:00 AM"
I'm using the tmap to push the file to a toutputdelimited (CSV). The format of the fields with "12/30/1899 00:00:00 AM" is coming back as "#######################." Any ideas on how to handle the situation would be great. The output date format is "yyyy-MM-dd HH:mm:ss"
Again, all other fields are converting as they should. Its only the special case "12/30/1899 00:00:00 AM" that is causing problems.
Thans!
Since your dates can be of different formats, you need to read your column as a String type in your tFileInputDelimited, then inside a tMap, check the date type (a simple way to check it is by testing its length) and parse it using the correct date format:
tFileInputDelimited -- tMap -- output
In a tMap expression, you can have something like this :
row.created_ts.length() == 22 ? TalendDate.parseDate("yyyy-MM-dd hh:mm:ssX", row.yourdate) : TalendDate.parseDate("yyyy-MM-dd hh:mm:ss.SSSSSSX", row.yourdate)

Lua 24-hour format of an hour without leading zeros

I need to get the act hour in Lua without the leading zeros(in 24 hour mode)
it's like date("G") in PHP
I actually have this code
os.date("%d-%m-%Y %H")
but it returns me 01 , 02 , 03 .... and I need to get 1 , 2, 3 etc
I found this but it doesn't seem to help me to solve my problem
os.date formats
You can just remove the leading zero:
os.date("%d-%m-%Y %H"):gsub(" 0"," ")
Try to get hour :
local hour = os.date("%H")
And try to format with string.format :
string.format("%d", hour)