Question

Between operator not working in my code. Please help me

    date_default_timezone_set('Asia/Kolkata');
    $today = date("m/d/y");
    $newdate = strtotime ( '-7 day' , strtotime ( $today ) ) ;
    $newdate = date ( 'm/d/y' , $newdate );  

    $query = mysqli_query($con, "SELECT * FROM service_calls WHERE open_date BETWEEN '$today' AND '$newdate'" );

It is giving me blank window after running this code.

I have open_date with format same as mentioned above.

Was it helpful?

Solution

Because in your database the date is in Y-m-d format, use this

date_default_timezone_set('Asia/Kolkata');
$today = date("Y-m-d");
$newdate = strtotime ( '-7 day' , strtotime ( $today ) ) ;
$newdate = date ( 'Y-m-d' , $newdate ); 

OTHER TIPS

First - on blank pages in general
Second - on mysqli errors in particular
Third - you have to use proper Mysql date format (which is Y-m-d) in your table and queries

finally, you don't need PHP for such a query

SELECT * FROM service_calls 
    WHERE open_date BETWEEN CURDATE() AND CURDATE() - INTERVAL 7 DAY;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top