mysql search berween two date?[SOLVE]

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

mysql search berween two date?[SOLVE]

Post by jayson.ph »

Hi all,

I am doing some search in which my requirment is to search between specific dates.
Like user can put start date and then end date. Once submit then it should find result between these two dates but how ever how can avoid not to show the empty end date value?
Last edited by jayson.ph on Fri Sep 07, 2012 4:53 am, edited 1 time in total.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mysql search berween two date?

Post by requinix »

So only a start date?

Code: Select all

if ($start and $end dates) {
    date condition = "date field BETWEEN $start AND $end";
} else if (only $start) {
    date condition = "date field >= $start";
} else { // only $end
    date condition = "date field <= $end";
}

query = "SELECT ... WHERE $date condition";
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

Re: mysql search berween two date?[SOLVE]

Post by jayson.ph »

Thank you requinix-
Post Reply