We recommend switching to the latest versions of Edge, Firefox, Chrome or Safari. Using Internet Explorer will result in a loss of website functionality.

Convert string year to integer or date?

Comments

3 comments

  • Avatar
    Adrian Williams

    The simplest approach would be to convert the Year string to an integer value and then compare it with 2020. 

    If the field to be tested contained a date string you could strip out the year character from the rest of the date [e.g. using the left() function] before converting it to an integer. You could alternatively convert the date string to a date type and then use the dateSubtract() function to compare it with a threshold date of 2020-01-01. Using the date functions is more processsor intensive than using numeric comparisons so the first option is probably the fastest method. However, you may will need to use the dateSubtract() function to compare two arbitrary date values.

    Note, you will need to handle Null values in your code unless the value to be tested can never be Null. 

     

    1
    Comment actions Permalink
  • Avatar
    Adrian Williams

    Here is an example of the different methods

     

    Attached files

    Compare_Year_Values.brg

     

    1
    Comment actions Permalink
  • Avatar
    Shawn Pelletier

    This worked beautifully, thanks for the example!

    0
    Comment actions Permalink

Please sign in to leave a comment.