How to correctly compare dates? I’m trying to crea...
# general
l
How to correctly compare dates? I’m trying to create a formula that says if the transaction date creation is after Sept. 9th, 2023, then show ‘A’ else ‘B’. I tried the following but neither worked. The “curly” quotes were just automatically converted by Slack. Our date format is DD.MM.YYYY. TO_DATE(TO_CHAR({datecreated},‘dd.mm.yyyy’)) > TO_DATE(‘05.09.2023’) - results in invalid expression error TO_CHAR({datecreated},‘dd.mm.yyyy’) > ‘05.09.2023’ - results in incorrect results
j
Try: TO_DATE({datecreated},‘dd.mm.yyyy’) > TO_DATE(‘05.09.2023’,’dd.mm.yyyy’)
m
CASE WHEN {datecreated} > TO_DATE('09.09.2023', 'DD.MM.YYYY') THEN 'A' ELSE 'B' END
If date created is not in correct format CASE WHEN TO_DATE(TO_CHAR({datecreated}, 'DD.MM.YYYY'), 'DD.MM.YYYY') > TO_DATE('09.09.2023', 'DD.MM.YYYY') THEN 'A' ELSE 'B' END
l
Aha. Was the error because I was comparing a string with a date? So I had to do the TO_DATE for the hard-coded date? Thanks though