最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sql - How to get EVENT based on startday, using BETWEEN

programmeradmin1浏览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 !

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 !

Share Improve this question edited Jul 17, 2019 at 11:42 Gregory asked Jul 17, 2019 at 9:19 GregoryGregory 6025 silver badges20 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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

Try this

WHERE dstart BETWEEN '$startdate' AND '$enddate'
发布评论

评论列表(0)

  1. 暂无评论