easy-digital-downloads
easy-digital-downloads copied to clipboard
3.0 - "Last Year" and "This Year" return incorrect dates (years) in SQL query
Bug Report
Expected behavior
When I select "Last Year" I expect to get 2021, and this year 2022. However I get one year behind for each.
Actual behavior
Here are the queries I get for "Earnings":
This Year:
SELECT SUM((total) / rate) AS total FROM wp_edd_orders WHERE 1=1 AND wp_edd_orders.status IN ('complete', 'partially_refunded', 'revoked') AND wp_edd_orders.type IN ('sale', 'refund') AND wp_edd_orders.date_created >= '2020-12-31 21:00:00' AND wp_edd_orders.date_created <= '2021-12-31 20:59:59'
Last Year:
SELECT SUM((total) / rate) AS total FROM wp_edd_orders WHERE 1=1 AND wp_edd_orders.status IN ('complete', 'partially_refunded', 'revoked') AND wp_edd_orders.type IN ('sale', 'refund') AND wp_edd_orders.date_created >= '2019-12-31 21:00:00' AND wp_edd_orders.date_created <= '2020-12-31 20:59:59'
You can see the years are completely wrong...
Information (if a specific version is affected):
PHP Version: 8.0
EDD Version (or branch): latest
WordPress Version: 6.0.1
Any other relevant information:
This fixes it:
case 'this_year':
$dates = array(
'start' => $date->copy()->startOfYear(),
'end' => $date->copy()->endOfYear(),
);
break;
case 'last_year':
$dates = array(
'start' => $date->copy()->subYear( 1 )->startOfYear(),
'end' => $date->copy()->subYear( 1 )->endOfYear(),
);
break;
@davidsherlock Can you verify this on the latest release 3.0.3? I'm trying to replicate locally and this is working as expected.
Not able to replicate it on 3.0.3: Last year:
WHERE date_created >= '2021-01-01 00:00:00'
AND date_created <= '2021-12-31 23:59:59'
This year:
WHERE date_created >= '2022-01-01 00:00:00'
AND date_created <= '2022-12-31 23:59:59'
Thanks for checking @mihaijoldis I'll close this for now and we can re-open if we get further information.