LAE

 View Only
  • 1.  Convert string year to integer or date?

    Employee
    Posted 03-22-2021 08:30

    I'm trying to filter data based on year, for instance I want all data from field "Year" < 2020 or older than 2020. The year field input is string type. Whats the best way to achieve the results I'm looking for?



  • 2.  RE: Convert string year to integer or date?

    Employee
    Posted 03-23-2021 10:23

    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. 

     



  • 3.  RE: Convert string year to integer or date?

    Employee
    Posted 03-23-2021 10:24

    Here is an example of the different methods

     

    Attached files

    Compare_Year_Values.brg

     



  • 4.  RE: Convert string year to integer or date?

    Employee
    Posted 03-24-2021 05:09

    This worked beautifully, thanks for the example!