Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

akmadhwa's avatar

Date interval between using where

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 .

0 likes
2 replies
ahmeddabak's avatar
Level 47

You are checking if the start_date bigger then both dateInStart and dateInStart

and the end_date smaller then both dateInStart and dateInEnd

are you sure this is what you want?

1 like
akmadhwa's avatar

@ahmeddabak thank you ive realize my mistake due to issue that you mention i unable to get the right result. Fixed it using query calling from repository and done. Thank you for answering my question. thank you so much

Please or to participate in this conversation.