Skip to main content
Solved

Function to test if date field is empty or null


Forum|alt.badge.img+4

I created a table called Items (household items).  In Items, there is a partially filled-out field, PurchaseDate, that is some items have a PurchaseDate; other items don't have a Purchase Date (field is left blank).  I want to run a filter of those items with a blank PurchaseDate:  Is the best way to do this is to create a formula field, named noPurchDate: LEN(DATESTR({PurchaseDate))=0 such that if the PurchaseDate is not empty, noPurchDate returns FALSE, and if PurchaseDate is empty, then NoPurchDate returns TRUE? Is there an easier way to get this result? 

Another more "normalized" way of handling this might be to create a separate table, PurchasesWithDates linking Items to PurchasesWithDates.  How does one create a filter of Items with no link to PurchasesWithDates?

 

Best answer by Sho

This is okay too

IF({PurchaseDate}, "hasDate", "hasNoDate")

Also, have you tried filtering date fields with "is empty"?

View original
Did this topic help you find an answer to your question?

Forum|alt.badge.img+4
  • New Participant
  • August 11, 2023

DATESTR() seems not to be able to handle empty sets nicely, but BLANK() does, so instead of LEN(DATESTR()), here's what I found does work:

IF({PurchaseDate} = BLANK(), "hasNoDate", "hasDate"). 

If the name of the field name is hasPurchaseDate, then IF({PurchaseDate} = BLANK(), FALSE(), TRUE()) works OK;  It would be even better if AirTable had a Logical primitive value or the resulting format would be T/F or perhaps a checkbox. 


Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • Answer
  • August 12, 2023

This is okay too

IF({PurchaseDate}, "hasDate", "hasNoDate")

Also, have you tried filtering date fields with "is empty"?


Forum|alt.badge.img+4
  • New Participant
  • August 14, 2023
Sho wrote:

This is okay too

IF({PurchaseDate}, "hasDate", "hasNoDate")

Also, have you tried filtering date fields with "is empty"?


Sho, 

Filtering date fields with "is empty" does do the trick.  Forgot to croll al the way down to find that option!  (How embarrassing!)  Thanks for your tips.


Reply