3 months ago

Date interval between using where

Posted 3 months ago by akmadhwa

I tried to check if the date input is in between the start_date and end_date inside the database. but as it seems the value is not included when i try to check, it returns a false as output?

Example code :

$dateInStart = date("Y-m-d H:i:s",strtotime($data['start_date'])); //date input start $dateInEnd = date("Y-m-d H:i:s",strtotime($data['end_date']));//date input end

$checkDbStart = DB::table('campaigns')->where('start_date','>=', $dateInStart)->where('end_date','<=', $dateInStart)->where('start_date','>=', $dateInEnd)->where('end_date','<=', $dateInEnd)->exists();

example input : $dateInStart = "2020-02-06 00:00:00"; $dateInEnd = "2020-02-07 00:00:00";

//value in db //start_date = 06-02-2020 //end_date =09-02-2020

How to include the value of input cause if i try using the ifelse condition i am able to get the value as it included. But for date as I test it does not include the input value .

Please sign in or create an account to participate in this conversation.