Skip to main content

Hi guys,

I have a table with an attribute 'Ingebruikname'.

This field contains a year, month and day and info in hours. For example: 2019-01-11T13:05:00.000. I created a regular expression to select only the part with information about year, month and day. Like:

2019-01-11T13:05:00.000

I would like to get my attribute 'Ingebruikname' updated to records with only date infromation as shown in bolt. Records with no data for 'Ingebruikname' should be included as well and left empty.

Do you have any ideas how to solve?

 

 

Hi @lambertus, the original datetime is formatted with ISO standard. I would try using the DateTimeConverter in this case, as in:


Hi @lambertus, the original datetime is formatted with ISO standard. I would try using the DateTimeConverter in this case, as in:

Hi @takashi, thanks for your fast reply! It works almost fine! I converted most records to a suitable output, ISO standard. However, I am left with 33 records which did not contain data. I would like to store them also in the attribute 'Ingebruikname'. Finally, I would like to have an attribute with a ISO standard date or empty.


I agree with @takashi.

However, you mentioned that you wanted to solve this using RegEx. In that case you can use e.g. @ReplaceRegEx(@Value(ingebruikname),^([0-9]{4}-[0-9]{2}-[0-9]{2}).+$,\\1). What you do is replacing the full string by the (first) set between ().

Another solution could be @Left(@Value(ingebruikname),10). This replaces the attribute value by the first 10 characters.

And you might as well use a DateTime function within an AttributeCreator or -Manager.


I agree with @takashi.

However, you mentioned that you wanted to solve this using RegEx. In that case you can use e.g. @ReplaceRegEx(@Value(ingebruikname),^([0-9]{4}-[0-9]{2}-[0-9]{2}).+$,\\1). What you do is replacing the full string by the (first) set between ().

Another solution could be @Left(@Value(ingebruikname),10). This replaces the attribute value by the first 10 characters.

And you might as well use a DateTime function within an AttributeCreator or -Manager.

Thanks for your reply! I used the AttributeManager in combination with your RegEx which works fine :)

What does the last part of your RegEx mean: +$\\1 ?

 


Hi @takashi, thanks for your fast reply! It works almost fine! I converted most records to a suitable output, ISO standard. However, I am left with 33 records which did not contain data. I would like to store them also in the attribute 'Ingebruikname'. Finally, I would like to have an attribute with a ISO standard date or empty.

What is it that you would like to store then, if you have no information?

And if you'd like to keep the original value, you could copy it using a AttributeCopier or -Manager before changing the attribute ingebruikname.


Thanks for your reply! I used the AttributeManager in combination with your RegEx which works fine :)

What does the last part of your RegEx mean: +$\\1 ?

 

I tried to explain that in the post. It takes the first result that is contained between (). If you just wanted the numbers you could use e.g. @ReplaceRegEx(@Value(ingebruikname),^((0-9]{4})-((0-9]{2})-((0-9]{2}).+$,\\1\\2\\3)

In your example \\1 would be 2019, \\2 would be 01 and \\3 would be 11


What is it that you would like to store then, if you have no information?

And if you'd like to keep the original value, you could copy it using a AttributeCopier or -Manager before changing the attribute ingebruikname.

My data is not that perfect. I want to leave the fields with no date empty or give them a default value like 9999.


Hi @lambertus, the original datetime is formatted with ISO standard. I would try using the DateTimeConverter in this case, as in:

In order to keep empty attribute as-is, set "Yes" to the Passthrough nulls, empties, or missing parameter, shown in the screenshot I posted.

If you are using an old version of FME, the transformer may not have that parameter. In that case, you can just connect both the Output port and the <Rejected> port together to the subsequent transformer.


Hi @lambertus, the original datetime is formatted with ISO standard. I would try using the DateTimeConverter in this case, as in:

If you need to replace the attribute value with 9999 when it doesn't start with the correct date format "yyyy-mm-dd", this workflow could also be available, for example.


If you need to replace the attribute value with 9999 when it doesn't start with the correct date format "yyyy-mm-dd", this workflow could also be available, for example.

Thanks @takashi! I am going to try how I far get.


If you need to replace the attribute value with 9999 when it doesn't start with the correct date format "yyyy-mm-dd", this workflow could also be available, for example.

Which transformer do you use to combine both these outputs?


I agree with @takashi: when working with dates and times, really try using the DateTime functions and transformers, rather than RegEx. RegEx is very powerful, but is also known to be a memory hogger when used a bit too leniently; in particular when using 'match-anythings' like .+ and .*


Which transformer do you use to combine both these outputs?

It depends on what you need to perform next. If you just want to check the result, for example, connect an Inspector and run.


Reply