Can't parsing String to Date&Time

Continuing the discussion from Parsing String to Date&Time:

I’ve tried applying the examples in the discussion above, it’s just that it still doesn’t work in my case, even though I think all formats are the same.

this is my configuration in String to Date&Time Node:

And this is my data structure :
28 Jul 2023 21:34:27 +0700
28 Jul 2023 21:30:00 +0700

But the result is empty
image

Why did it happen?

Hi @veniapputrii ,

I made some tests and the result is about your string from date format. Maybe you can simplify the string for just date using string manipulation and then, use string to date&time node to adjust it as below.

Before: 28 Jul 2023 23:34:47 +0700

After: 28/Jul/2023

regexReplace($Date$,"(\\d+) ([a-zA-Z]+) (\\d+) (\\d+:\\d+:\\d+) (\\++\\d+)","$1/$2/$3")

As you can see, i set just a date for it, and put a slash (/) to split date, month and year as a “real date statement” > 28/Jul/2023.

image

Then, it works for me to use it:

image

That’s not the answer that I’d like to pass, but if it resolve your problem, could you apply it from now.

BR,

Denis

1 Like

Hi,

I made some quick tests, and a time/date format in the String to Date&Time node like

28 Jul 2023 23:34:47 +0700

can be converted to a standard date with

You almost had it but you need to specify ‘Date’ (not Date&Time), and use explicit spaces in the format string, as well as the optional indicator (the brackets) to enable it to be converted to a date only.

Screenshot 2023-07-31 at 19.28.21

Hope this helps,
Sam

2 Likes

@veniapputrii it seems at least on a Mac with KNIME 4.7.6 this setting seem to work

dd MMM yyyy HH:mm:ss Z

kn_forum_71236_string_to_date_id.knwf (30.2 KB)

2 Likes

Thankyou so much @denisfi , @mlauber71 , @ssq for your help…
But, All the suggestions from you haven’t worked on my node yet. The result is still the same, showing an empty result.
I got the date data from the rss site that I had previously extracted.
image

Hi @veniapputrii , I think I discovered your problem from “forensically” :wink: examining your screenshot:

Yours:

and comparing it to one I produced using the “same” data.

Mine:

You have spaces at the start of your dates! Trim them with String Manipulation and then try the solutions again. I think you will find the solutions are correct, but the data was wrong :slight_smile:

The post by @mlauber71 has the correct format mask once the dates are trimmed.

3 Likes

Hi!

Well I have problem with string to time zone… I simplify the date string direct from the source as the workflow added.

rss_date.knwf (17.8 KB)

I saw that the link tag have date structure for the information too:

<item>
<title>
<![CDATA[ BREAKING NEWS: Bareskrim Polri Tetapkan Panji Gumilang Tersangka Kasus Penistaan Agama hingga Ujaran Kebencian ]]>
</title>
<link>https://www.suara.com/news/2023/08/01/214552/breaking-news-bareskrim-polri-tetapkan-panji-gumilang-tersangka-kasus-penistaan-agama-hingga-ujaran-kebencian</link>
<description>
<img src="https://media.suara.com/pictures/970x544/2023/08/01/51556-diretipidum-bareskrim-polri-brigjen-pol-djuhandhani-rahardjo-puro.jpg" align="left" hspace="7" width="100" />
<![CDATA[ "Menetapkan saudara PG sebagai tersangka," kata Ramadhan. ]]>
</description>
<enclosure length="10240" type="image/jpeg" url="https://media.suara.com/pictures/970x544/2023/08/01/51556-diretipidum-bareskrim-polri-brigjen-pol-djuhandhani-rahardjo-puro.jpg"/>
<category>
<![CDATA[ Kasus penistaan agama ]]>
</category>
<category>
<![CDATA[ ujaran kebencian ]]>
</category>
<category>
<![CDATA[ Panji Gumilang ]]>
</category>
<category>
<![CDATA[ pimpinan ponpes al zaytun ]]>
</category>
<category>
<![CDATA[ bareskrim polri ]]>
</category>
<pubDate>Tue, 01 Aug 2023 21:45:52 +0700</pubDate>
<guid isPermaLink="false">https://www.suara.com/news/2023/08/01/214552/breaking-news-bareskrim-polri-tetapkan-panji-gumilang-tersangka-kasus-penistaan-agama-hingga-ujaran-kebencian</guid>
</item>

So you can work with some solutions here… step by step from my flow:

image

image

regexReplace($pubDate$,"^.*\\, ","")

To remove da Day name before the date.

regexReplace($pubDate$," [+-]\\d+$","")

Remove the timezone

I change the string from the date&time setting as:

dd MMM yyyy HH:mm:ss

That was the result… as I asked you, Do you need all information about the time or just a reference?

BR,

Denis

2 Likes

Thanks @takbb
can you share your writing expression?
It seems my writing is wrong

HI @veniapputrii ,

There is a strip() function in String Manipulation that you can use, which will remove spaces from beginning and end of the string. This will hopefully do what you need:

strip($date$)

2 Likes

Hello, @denisfi
Thankyou so much for your help !
I’m looking for similar references to solve my problem, as well as to learn more about the time.
I’ve imported the workflow from you, and step by step I implemented it in my workflow.

When I observed, it turns out that there is a difference in the column names between yours and mine.
yours on the Xpath node
Screenshot 2023-08-02 215920

And below is mine on Xpath node
Screenshot 2023-08-02 220119
in the Xpath Summary on the Column Name, I gave a column name that doesn’t match the name of the tag in the XML.
which should be the column name : pubdate according to the tag name.
Instead I named it “date

Maybe there’s a mistake there, that’s why I tried to change the column name according to the tag name, namely “pubdate

And all the solutions from these discussion mates work fine.

I think column names don’t have to be the same. But, I’m learning something new now.

Thank you very much, everyone !!

Best Regards,
Veni

1 Like

Hi @veniapputrii ,

From the XPath, you can set the name for the tag, so normally brings the original value from the path, but if you edit by double click for the field, you can set it as you wish. It helps me to define different names for the original tag for my flow, just it! :slight_smile:

Example:

I wish it can help you some time…

BR,

Denis

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.