Jump to content

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)
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.