conversion issue while putting transformer to read string having date values - date

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

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"))

How to convert particular string to date in 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).

looking for spark scala(java) code for date string with spaces in between with specific conditions

need some suggestions on below requirement.
Each response help a lot thanks in advance....
I have a date of type String with timestamp ex: Jan 8 2019 4:44 AM
My requirement is if the date is single digit I want date to be 1 space and digit
(ex: 8) and if the date is 2 digits which is dates from 10 to 31 I want date with no space(ex:10) and also same for hour in timestamp.
to summarize: if the date is 1 to 9 and hour in timestamp is 1 to 9 looking for below string
Jan 8 2019 4:44 AM
if the date is 10 to 31 and hour in timestamp is 10 to 12 looking for below string
Jan 18 2019 12:44 AM
right now I am creating a date in following way:
val sdf = new SimpleDateFormat("MMM d yyyy h:mm a")
but the above format satisfies only one condition which is dates from 1 to 9.
my application is spark with scala so looking for some spark scala code or java.
I appreciate your help...
Thanks..
java.time
Use p as a pad modifier in the format pattern string. In Java syntax (sorry):
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
"MMM ppd ppppu pph:mm a", Locale.ENGLISH);
System.out.println(LocalDateTime.of(2019, Month.JANUARY, 8, 4, 44)
.format(formatter));
System.out.println(LocalDateTime.of(2019, Month.JANUARY, 18, 0, 44)
.format(formatter));
Jan 8 2019 4:44 AM
Jan 18 2019 12:44 AM
And do yourself the favour: Forget everything about the SimpleDateFormat class. It is notoriously troublesome and fortunately long outdated. Use java.time, the modern Java date and time API.
Link: Oracle tutorial: Date Time explaining how to use java.time.
To quote the DateTimeFormatter class documentation:
Pad modifier: Modifies the pattern that immediately follows to be padded with spaces. The pad width is determined by the number of pattern letters. This is the same as calling DateTimeFormatterBuilder.padNext(int).
For example, 'ppH' outputs the hour-of-day padded on the left with spaces to a width of 2.

How to enter a YYYYMM date in Jekyll?

How should dates be entered in Jekyll?
I would like to enter the date "August 2018" in a YAML file to be used in Jekyll. I find lots of information on how to format already-existing dates, but pretty much nothing on how to enter them.
The best I have managed to find is Date formatting, which implies that dates entered in ISO 8601 format should be valid. If I run with this, then Wikipedia explicitly states
"2004-05" is a valid ISO 8601 date, which indicates May (the fifth
month) 2004.
This implies that "August 2018" could be entered as 2018-08.
However, when I use my YAML file my_data.yml in my _data folder
date: 2018-08
then Jekyll doesn't recognize it as a date as
{{ site.data.my_data.date | time: '%B %Y' }}
outputs "2018-08" and not "August 2018".
TL;DR: Enter YYYYMM dates such as "August 2018" as Aug 2018.
Searching through the Jekyll repo, I found the date filters. The Ruby on Rails method .to_formatted_s (source) seem to be key to most of them. In the source to that method dates are written as Tue, 04 Dec 2007 00:00:00 +0000 from which I guessed that I should write Aug 2018. Doing so in my_data.yml, the code outputs the expected “August 2018”.

How do I parse "YYYY-MM-DD" with joda time

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");