Jump to content

Need help with the date syntax


eldan88

Recommended Posts

Hey Guys. My previous developer wrote the following date syntax and I am trying to understand what it means, as I never seen a syntax like that.

 

Particular this ....

AND MONTH(`checkout_date`) = MONTH(CURRENT_DATE - INTERVAL $month_skip_number MONTH) 
AND YEAR(  `checkout_date` ) = YEAR( CURRENT_DATE )

Is he assigning the files value to the current month and year??

 

Below is the full syntax

$checkout = "SELECT DAY(`checkout_date`) AS days, count(`checkout_date`) AS total_checkouts, sum(cart_total) AS total  
FROM  `checkout` 
WHERE `store_id`= $store_id 
AND MONTH(`checkout_date`) = MONTH(CURRENT_DATE - INTERVAL $month_skip_number MONTH) 
AND YEAR(  `checkout_date` ) = YEAR( CURRENT_DATE ) 
GROUP BY days";
Link to comment
https://forums.phpfreaks.com/topic/285043-need-help-with-the-date-syntax/
Share on other sites

He's checking a couple of conditions, not assigning anything.

MONTH(`checkout_date`) = MONTH(CURRENT_DATE - INTERVAL $month_skip_number MONTH)
That checks if the MONTH portion of the date stored in checkout_date is equal to the MONTH portion of the current date less $month_skip_number months.

 

YEAR(  `checkout_date` ) = YEAR( CURRENT_DATE )
This checks if the YEAR portion of the date stored in checkout_date matches the current year.

also, the date math isn't doing what you expect. by only modifying the month, trying to go back past the start of the year, will try to find dates in the future. use this -

EXTRACT(YEAR_MONTH FROM checkout_date) = EXTRACT(YEAR_MONTH FROM CURRENT_DATE - INTERVAL $month_skip_number MONTH)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.