Skip to main content
Solved

Validate Date field


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)

^....$
View original
Did this help you find an answer to your question?

5 replies

takashi
Influencer
  • 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
takashi wrote:

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+32
  • 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
Influencer
  • August 22, 2017
ebygomm wrote:

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+32
  • Influencer
  • August 22, 2017
takashi wrote:
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 :-)

 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings