get data between two dates in php

hii all
 i want to fetch data from database between two dates.
 startdate and end_date are like (2018-04-04) and database column name datetime has a value date and time like (2018-04-04 12:05:07).
Both dates(startdate and end_date ) check with datetime column in database.
i am using query (select * from table where datetime>=startdate and datetime<=end_date). if i select both dates same like(2018-04-04 and 2018-04-04) then this query is not working. please help me how to do this?
Deepak SinghWeb DeveloperAsked:
Who is Participating?
 
Dave BaldwinFixer of ProblemsCommented:
Entering '2018-04-04' is the same as entering '2018-04-04 00:00:00'.  If you enter it for both dates, there can't possibly be anything between them.  Since MySQL automatically assumes the '00:00:00' part, I would use the next day for the end_date.  It would then be between '2018-04-04 00:00:00' and '2018-04-05 00:00:00' which covers 24 hours of '2018-04-04'.
2
 
NerdsOfTechTechnology ScientistCommented:
You can do exactly what @Dave said. If we knew which database you were using we could even help you with the query syntax, etc.
0
 
NerdsOfTechTechnology ScientistCommented:
Notwithstanding the database used, by using the day of and the next day's date for the BETWEEN parameters, a full day query can be constructed, as illustrated by Dave's comment.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.