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)
Related
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}")&"/"®exextract(A1,"\D+ (\D+) ")&"/"®exextract(A1,".* (\d+)"))))
or (with hours/minutes/seconds)
=arrayformula(if(A1:A="",,1*(regexextract(A1,"\d{2}")&"/"®exextract(A1,"\D+ (\D+) ")&"/"®exextract(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"))
I'm trying to get DAYID as string in format YYYYMMDD, however its not working correctly.
I have a timestamp field, I take first 10 characters and convert it into date (working correctly)
toDate(substring(EventTimestamp,1,10))
-- 2021-03-24
However when I try to convert to string using below expression, I;m getting wrong answer. I;m getting the Day as 83.
toString(toDate(substring(EventTimestamp,1,10)),'YYYYMMDD')
--20210383
Date format characters are case-sensitive as per this answer here, so use yyyyMMdd instead.
An example using formatDateTime:
#formatDateTime(utcnow(), 'yyyyMMdd')
I have a number of date/time entries in a spreadsheet which I wish to reformat as follows
10/20/2014 13:00:00 (mm/dd/yyyy hh:mm:ss) to show as 20/10/2014 PM
10/01/2014 08:00:00 (mm/dd/yyyy hh:mm:ss) to show as 01/10/2014 AM
I can convert and split the date out easily enough but I cannot get the hh:mm:ss to show as simply AM or PM.
Thanks
Under Format Cells, choose the Number tab, select Custom, and enter this format:
dd/mm/yyyy AM/PM
You can also do this using the TEXT function:
=TEXT(Date,"dd/mm/yyyy AM/PM")
I am trying to copy data from Excel to a SQL table.
I have dates generated in Excel file using RAND function. I am taking them as strings in an input and trying to convert them in date data type using tConvertType.
I have setted its datatype as 'string' in initial input and as 'date' in tConvertType's output and in tMSSqlOutput.
My job has work flow Excel input -> tConvertType -> tMap -> tMSSqlOutput.
While running the job I am getting an error which says :
java.text.ParseException: Unparseable date: "Tue Jul 17 00:00:00 EDT 1973"
I am not sure where the problem lies.
If anyone could help me with this it would be much appreciated.
Here's the screenshot of my job.
i am able to parse your given sample date please use below function in tMap for your date filed.
System.out.println(TalendDate.parseDateLocale("EEE MMM dd HH:mm:ss zzz yyyy", 'Tue Jul 17 00:00:00 EDT 1973', "EN"));
function is yourDateColumn!=null && !"".equalsIgnoreCase(yourDateColumn)? TalendDate.parseDateLocale("EEE MMM dd HH:mm:ss zzz yyyy", yourDateColumn, "EN") :null
#UmeshR: your code is working fine, but you have to handle the timezone thing as well. e.g. I am from India and when i converted the time from EDT talend converted it to my local timezone. see the screen-shot.
I'm trying to use joda-time to parse a date string of the form YYYY-MM-DD. I have test code like this:
DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("YYYY-MM-DD");
DateTime dateTime = dateDecoder.parseDateTime("2005-07-30");
System.out.println(dateTime);
Which outputs:
2005-01-30T00:00:00.000Z
As you can see, the DateTime object produced is 30 Jan 2005, instead of 30 July 2005.
Appreciate any help. I just assumed this would work because it's one of the date formats listed here.
The confusion is with what the ISO format actually is. YYYY-MM-DD is not the ISO format, the actual resulting date is.
So 2005-07-30 is in ISO-8601 format, and the spec uses YYYY-MM-DD to describe the format. There is no connection between the use of YYYY-MM-DD as a pattern in the spec and any piece of code. The only constraint the spec places is that the result consists of a 4 digit year folowed by a dash followed by a 2 digit month followed by a dash followed by a two digit day-of-month.
As such, the spec could have used $year4-$month2-$day2, which would equally well define the output format.
You will need to search and replace any input pattern to convert "Y" to "y" and "D" to "d".
I've also added some enhanced documentation of formatting.
You're answer is in the docs: http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html
The string format should be something like: "yyyy-MM-dd".
The date format described in the w3 document and JodaTime's DateTimeFormat are different.
More specifically, in DateTimeFormat, the pattern DD is for Day in year, so the value for DD of 30 is the 30th day in the year, ie. January 30th. As the formatter is reading your date String, it sets the month to 07. When it reads the day of year, it will overwrite that with 01 for January.
You need to use the pattern strings expected by DateTimeFormat, not the ones expected by the w3 dat and time formats. In this case, that would be
DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("yyyy-MM-dd");