eldan88 Posted January 2, 2014 Share Posted January 2, 2014 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"; Quote Link to comment https://forums.phpfreaks.com/topic/285043-need-help-with-the-date-syntax/ Share on other sites More sharing options...
kicken Posted January 2, 2014 Share Posted January 2, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/285043-need-help-with-the-date-syntax/#findComment-1463620 Share on other sites More sharing options...
mac_gyver Posted January 2, 2014 Share Posted January 2, 2014 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) Quote Link to comment https://forums.phpfreaks.com/topic/285043-need-help-with-the-date-syntax/#findComment-1463623 Share on other sites More sharing options...
eldan88 Posted January 3, 2014 Author Share Posted January 3, 2014 Thanks for the clarification Kicken. mac_gyver. Thank you for pointing that out.... what is the "INTERVAL" supposed to stand for? Quote Link to comment https://forums.phpfreaks.com/topic/285043-need-help-with-the-date-syntax/#findComment-1463764 Share on other sites More sharing options...
mac_gyver Posted January 3, 2014 Share Posted January 3, 2014 all your basic mysql questions are answered here - http://dev.mysql.com/doc/refman/5.6/en/index.html Quote Link to comment https://forums.phpfreaks.com/topic/285043-need-help-with-the-date-syntax/#findComment-1463768 Share on other sites More sharing options...
eldan88 Posted January 4, 2014 Author Share Posted January 4, 2014 Okay Will do. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/285043-need-help-with-the-date-syntax/#findComment-1463774 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.