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

• 0
• Question
• Updated 1 year ago
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.

• 256 Points

Posted 1 year ago

• 0
• 4,430 Points

try

If(

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

)

Ⲇanom the ultimate (Dan Diebolt), Champion

• 30,364 Points
`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
• 4,430 Points
If [Period Tested] is a Date/Time field, you'll need to use the ToDate() function on [Period tested] too.
• 256 Points
Thanks Chris and Dan, the ToDate() function worked fine in this scenario!