Skip to main content
Solved

Validate Date field

  • August 22, 2017
  • 5 replies
  • 345 views

rclarkenz
Contributor
Forum|alt.badge.img+2

I have a date field in my excel document which I am reading into FME that contains a mixture of dd/mm/yyyy and dd/mm/yy. Unfortunately, some of the fields just have the year, e.g. 1951. with no date or month.

What I'm trying to figure out is how to find just those features that have a year in the date field and then return only those to the inspector.

I looked at AttributeValidator but I see it does not have Date as a Rule configuration under Type.

Best answer by takashi

Hi @rclarkenz, I think that it's a quick way to use the Tester (Contains Regex operator) to determine if the attribute value has just four characters. There should be several ways other than that.

0684Q00000ArJjQQAV.png

Right Value (regular expression that matches a string consisting of just four characters)

^....$
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

takashi
Celebrity
  • Best Answer
  • August 22, 2017

Hi @rclarkenz, I think that it's a quick way to use the Tester (Contains Regex operator) to determine if the attribute value has just four characters. There should be several ways other than that.

0684Q00000ArJjQQAV.png

Right Value (regular expression that matches a string consisting of just four characters)

^....$

rclarkenz
Contributor
Forum|alt.badge.img+2
  • Author
  • Contributor
  • August 22, 2017

Hi @rclarkenz, I think that it's a quick way to use the Tester (Contains Regex operator) to determine if the attribute value has just four characters. There should be several ways other than that.

0684Q00000ArJjQQAV.png

Right Value (regular expression that matches a string consisting of just four characters)

^....$
Thanks @takashi. I ended up also checking the length of the string in a Tester. If the string was 5 or less, then it mustn't be a correctly formatted date.  

 


ebygomm
Influencer
Forum|alt.badge.img+46
  • Influencer
  • August 22, 2017

To genuinely check if a date is valid, i.e. to reject a date such as 31/02/2017 requires some python.

Probably not required for you if the requirement is only to identify cases with only a year value populated.


takashi
Celebrity
  • August 22, 2017

To genuinely check if a date is valid, i.e. to reject a date such as 31/02/2017 requires some python.

 Probably not required for you if the requirement is only to identify cases with only a year value populated.

Hi @egomm, in FME 2017.0+, Python scripting is not essential.

 

Tips:

 

In FME 2017.0+, the @DateTimeParse function can be used to determine if a date/time value is valid or not.

 

@DateTimeParse(28/02/2017,%d/%m/%Y) returns "20170228"
@DateTimeParse(31/02/2017,%d/%m/%Y) returns <null>
@DateTimeParse(31/02/2017,%d/%m/%Y,repair) returns "20170303"
In FME 2017.1+, the DateTimeConverter can also be used to filter features based on the date/time validation result. That is, the transformer rejects the input feature if a specified date/time attribute value is invalid, by default  (Repair Overflow: No).

 


ebygomm
Influencer
Forum|alt.badge.img+46
  • Influencer
  • August 22, 2017
Hi @egomm, in FME 2017.0+, Python scripting is not essential.

 

Tips:

 

In FME 2017.0+, the @DateTimeParse function can be used to determine if a date/time value is valid or not.

 

@DateTimeParse(28/02/2017,%d/%m/%Y) returns "20170228"
@DateTimeParse(31/02/2017,%d/%m/%Y) returns <null>
@DateTimeParse(31/02/2017,%d/%m/%Y,repair) returns "20170303"
In FME 2017.1+, the DateTimeConverter can also be used to filter features based on the date/time validation result. That is, the transformer rejects the input feature if a specified date/time attribute value is invalid, by default  (Repair Overflow: No).

 

I will look forward to using that functionality, probably sometime mid 2018 :-)