0

I have a SQL query that get all events ordering by Startdate, and i define startday as $today.

but this query didn't take events that start yestarday and that endday is tomorow.

how can i make my query to use BETWEEN ?

my query

SELECT * FROM wp_posts, `wp_mec_dates` AS mecd, wp_icl_translations WHERE wp_posts.ID = mecd.post_id and post_status='publish' AND wp_icl_translations.language_code='$lang' AND dstart>'$startday' and  wp_posts.ID = wp_icl_translations.element_id ORDER BY dstart LIMIT 0,6

startdate is $startday = date("Y-m-d");

EDIT : with documentation & help, i'm here now :

SELECT * FROM wp_posts, wp_mec_dates AS mecd, wp_icl_translations WHERE wp_posts.ID = mecd.post_id and post_status='publish' AND wp_icl_translations.language_code='$lang' AND ($startday BETWEEN dstart AND dend)AND  wp_posts.ID = wp_icl_translations.element_id ORDER BY dstart LIMIT 0,6

but it return 0 results. Any help will be apreciated !

0

found the solution <3

Used WHERE '$startday' BETWEEN dstart AND dend

plus : OR dstart >= '$startday'

SELECT * FROM wp_posts, wp_mec_dates AS mecd, wp_icl_translations WHERE wp_posts.ID = mecd.post_id and post_status='publish' AND wp_icl_translations.language_code='$lang' AND ('$startday' BETWEEN dstart AND dend OR dstart >= '$startday') AND  wp_posts.ID = wp_icl_translations.element_id ORDER BY dstart LIMIT 0,6
-1

Try this

WHERE dstart BETWEEN '$startdate' AND '$enddate'
  • hello, what do i set as "enddate" ? – Gregory Jul 17 '19 at 11:15
  • for example: $startdate = '2019-07-16' AND $enddate = '2019-07-18' – user2243593 Jul 17 '19 at 13:09
  • yes, but i didn't know enddate ;-) perhaps, i found a solution investigating your idee. See my answear. – Gregory Jul 17 '19 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.