Please, can someone help me with this part of query? It's working fine in Microsoft Access but won't work in MySQL:
DateDiff("m",[first_sent_date],[last_sent_date])+1 AS basetime_month, Count(tablename.id) AS cnt_all
Please, can someone help me with this part of query? It's working fine in Microsoft Access but won't work in MySQL:
DateDiff("m",[first_sent_date],[last_sent_date])+1 AS basetime_month, Count(tablename.id) AS cnt_all
The Access SQL DateDiff function takes at least three (3) arguments. It returns different values based on the first argument, which is the "interval". In your case
DateDiff("m",[first_sent_date],[last_sent_date])
the "m"
indicates that you want the difference in months.
The MySQL DATEDIFF function only takes two (2) arguments and always returns the difference in days. The MySQL equivalent to the Access SQL DateDiff
expression above would be something like
((YEAR(`last_sent_date`) - YEAR(`first_sent_date`)) * 12) + MONTH(`last_sent_date`) - MONTH(`first_sent_date`)