简体   繁体   中英

get the data is greater than is equal todays date

I want to fetch all data from today's date(or greater than is equal today's date). But it shows all the date before and after todays date. See below images: 在此输入图像描述

My fetch query is : SELECT * FROM tbl_reservation_info WHERE ri_id !='' AND status = 'Success' AND ri_arrival_date > '08-Apr-2019'

Your dates are not in a valid MySQL date format (the column is presumably a VARCHAR or similar), and are being compared as strings. Since all your dates start with 1 , 2 , or 3 , they are all greater than (using a string comparison) a date string starting with 0 . You need to convert the formats to compare correctly:

SELECT * 
FROM tbl_reservation_info
WHERE ri_id !='' 
  AND status = 'Success' 
  AND STR_TO_DATE(ri_arrival_date, '%d-%b-%Y') > STR_TO_DATE('08-Apr-2019', '%d-%b-%Y')

Normally a Date is saved in following format : YYYY-MM-DD Perhaps your php-myadmin format it in this way or

you should change it from varchar/text to date otherwise sorting and filtering will be complicated. Also your code should use this format - for displaying you need to convert it.

In your screenshot the 12 is greater then the 8 you filtering.

12-Mar-2019 > 8*

https://dev.mysql.com/doc/refman/8.0/en/date-and-time-type-overview.html

https://www.php.net/manual/de/function.date.php

You can simply try CURDATE() :

SELECT * 
FROM tbl_reservation_info 
WHERE ri_id !='' AND status = 'Success' AND  ri_arrival_date > CURDATE();

With this, it skips today's date. if you want them to the add >=

Make sure ri_arrival_date is date format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM