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

mysql search berween two date?[SOLVE]

Postby jayson.ph » Mon Sep 03, 2012 11:28 pm

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
jayson.ph
Forum Contributor
 
Posts: 165
Joined: Mon Jan 02, 2012 10:20 am
Location: MP

Re: mysql search berween two date?

Postby requinix » Tue Sep 04, 2012 2:37 am

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";
Did you steal it?
User avatar
requinix
Spammer :|
 
Posts: 5509
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: mysql search berween two date?[SOLVE]

Postby jayson.ph » Fri Sep 07, 2012 4:53 am

Thank you requinix-
User avatar
jayson.ph
Forum Contributor
 
Posts: 165
Joined: Mon Jan 02, 2012 10:20 am
Location: MP


Return to Databases

Who is online

Users browsing this forum: No registered users and 2 guests