Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL query between 2 dates fields

Tags:

php

mysql

i am trying to create a MySQL query that will take current date and compare it to the 2 date fields that i have in my table and return the rows that satisfy that query.

here is my columns 1- [from_date] which type is Date 2- [to_date] which also holds type Date

the query suppose to return the rows that falls in between those dates.

here is my query

mysql_query("SELECT * FROM location WHERE from_date >= DATE() AND to_date <= DATE()")

my problem is that it doesn't return anything. should i switch my column type to DATETIME?

Thanks in advance.

like image 793
Hectorubie Avatar asked Mar 24 '23 22:03

Hectorubie


2 Answers

You should use Now() to get the current date of the system.

like image 112
Ahmed Z. Avatar answered Apr 01 '23 22:04

Ahmed Z.


See documentation here.
Use BETWEEN
mysql documentation here

like image 33
FrancisMarfo Avatar answered Apr 01 '23 22:04

FrancisMarfo