Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am trying to convert a string date to another string date but in a different format in a tMap expression. I need to first trim "HH:mm:ss" from the string and then remove the /'s and then flip the YYYY around. If anyone has any good resources to learn javascript string conversions and date conversions that would be greatly appreciated.
I am trying to convert this date that is currently in the csv I am working with "1/5/2018 11:39:30 AM" to "20180115" to load into a SQL Table that has this date format.
If anyone in Talend Community knows how to do this string conversion this would be a life saver!
TalendDate.formatDate("yyyyMMdd",TalendDate.parseDate("MM/dd/yyyy hh:mm:ss a",row1.strDate ))
Hey Vapukov,
I am still trying to keep it a String value and not convert it to a date value. I may have mislead you with my original message. That value "1/5/2018 11:39:30 AM" is being inputted as a String in my tMap component and for it stay to as an output for my SQL table but in a string "yyyyMMdd". I know I have to make a few variables to get the right format. I was thinking that my variable would consist of these String Functions
StringHandling.TRIM(StringHandling.LEFT(row1.stringdate,StringHandling.INDEX(row1.stringdate, " "))))
I'm just not sure if I need to split them up into seperate variables or keep them intact.
I just need some help manipulating the string into that format.
Thanks for the quick response before!
TalendDate.formatDate("yyyyMMdd",TalendDate.parseDate("MM/dd/yyyy hh:mm:ss a",row1.strDate ))
so all as described - Source is String, target is String
Hello Vapukov,
Goes to show you the knowledge I have with Talend JavaScript Expression Language LOL. I am new to Talend. I am still getting a ParseException error on :Jan, So I was reading the csv file in Excel instead of Notepad +++. I know Excel changes date formats of csvs. The date format is actually "Jan 12, 2018 05:13:48 AM" So I just need the syntax to change the Month abbreviation to the month number, so January would turn into 01. I still want the final output of the tmap to be "yyyyMMdd". This change should allow me to process the csv file to SQL table.
Thanks for the quick response again, Hopefully the next response will close this discussion and Kudos goes to you!
I was thinking would this be the expression now be
TalendDate.formatDate("yyyyMMdd",TalendDate.parseDate("MMM dd, yyyy hh:mm:ss aa",row1.stringdate))?
Exception in component tMap_2 (Email_Bounces)
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "Jan"
Not sure why its throwing this error
I made a Variable of Date:for this string type
"Jan 12, 2018 05:13:48 AM "
TalendDate.parseDate("MMM dd, yyyy HH:mm:ss aa",fixed.timestamp)
Then used this as my output column
TalendDate.formatDate("yyyyMMdd",Var.newdate)
If I am using a tfilelist.csv file will this affect my output? I was able to get the right output "YYYYMMDD" for this csv with a tjavarow output component