Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I have some problems understanding how to pass dates to Date#.
Could you please explain why this happens ?
let daterif = Date(today(),'YYYY-MM-DD');
let ok= Date#(daterif , 'YYYY-MM-DD');
let ko= Date#($(daterif ), 'YYYY-MM-DD');
trace $(ok); // this prints 2021-05-14
trace $(ko); // this prints 2002
trace datarif;
Why does "trace $(ko) " prints 2002?
Why does "trace $(ok)" prints the date in the correct format (without dollar expansion)?
Thanks.
Date#($(daterif ), 'YYYY-MM-DD'); <= contains a dollar expansion. So it calculates the expression 2021 minus 5 minus 14 first. The result of that calculation is 2002. The Date# function sees that 2002 does not have the format YYYY-MM-DD so it can't turn it into a date. And that's why it stays 2002.
Date#($(daterif ), 'YYYY-MM-DD'); <= contains a dollar expansion. So it calculates the expression 2021 minus 5 minus 14 first. The result of that calculation is 2002. The Date# function sees that 2002 does not have the format YYYY-MM-DD so it can't turn it into a date. And that's why it stays 2002.