Careful when comparing dates (STRFTIME format != MYSQL fmt)

should I use this workaround?

  • yes
  • no

0 voters

Because we had some holidays coming up I made a holiday routing: Asterisk looks up the current date in a MySQL database and routes the call differently when a match is found (meaning that the current date is a holiday).

I started in MySQL with the field type DATE. This represents dates in the format YYYY-MM-DD. In my Asterisk script I looked up the current date with the function “date=${STRFTIME(${EPOCH},%Y-%m-%d)}”.

Printing both date formats gives the samen result. String lengths are equal as well, but the script does NOT find a match. Changing the field format into VARCHAR(10) or CHAR(10) makes no difference. Typing the date string instead of the STRFTTIME function DOES give a match!

My workaroud: leave the dashes out. YYYYMMDD can be compared to %Y%m%d.

If anyone can explain the difference I would be glad to hear it (I prefer the date format in my database) but until then: be carefult with string comparison!