Using the equals(=) operator when referencing a date to a number in an IF statement

  • 0
  • 1
  • Question
  • Updated 5 months ago
  • Answered
I am looking to create a numeric formula field in a table.  I am looking to define a specific number based on the date in a field called "Period Tested".  For example:

If Period Tested = 01-01-2016, display the number "1"
If Period Tested = 02-01-2016, display the number "4"
etc.

I've written it out as such:

If([Period Tested]="01-01-2016",1,
[Period Tested]="02-01-2016",4)

I am using the Formula - Number type for the field.

I get the following error when I try to save:

The expression [Period Tested] on the left hand side of the operator "=" is of type date while the expression "01-01-2016" on the right hand side is of type text. The operator "=" cannot be used with these types of expressions.

I'm not sure how to circumvent that in the system exactly, but I need the final number to show based on the date from the Period Tested field.  Any idea how I can work around this?  I looked a bit and didn't find any operator that could replace the equals(=) in this scenario.  

Thanks for your time!
Photo of SammyS

SammyS

  • 256 Points 250 badge 2x thumb

Posted 5 months ago

  • 0
  • 1
Photo of Chris

Chris, Champion

  • 4,390 Points 4k badge 2x thumb

try

If(

[Period Tested]=ToDate("01-01-2016"),1,
[Period Tested]=ToDate("02-01-2016"),4

)

Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 27,694 Points 20k badge 2x thumb
If(
[Period Tested] = Date(2016, 1, 1), 1,
[Period Tested] = Date(2016, 2, 1), 4
)

Date(2000, 1, 10) returns the date January 10, 2000
Photo of Chris

Chris, Champion

  • 4,390 Points 4k badge 2x thumb
If [Period Tested] is a Date/Time field, you'll need to use the ToDate() function on [Period tested] too.
Photo of SammyS

SammyS

  • 256 Points 250 badge 2x thumb
Thanks Chris and Dan, the ToDate() function worked fine in this scenario!