In mysql contact_details table I've a column called created_date. I'm inserting date and time to this created_date column when I insert any new contact to that Table. Date and time is somethiing like this :
6/19/2013 18:25
6/19/2013 18:25
10/10/2014 17:25
Well, I've a Search form where 2 fields exist.
1) Date From.
2) Date To.
This 2 filed is pickup only Date (m/d/y) not TIME. Now I want to search data based on this 2 date. It's could be search Only Date From or Date To or Both.
1) Date From will be search Date From To Today date.
2) Date To will be search All data till Date To.
3) If both date exist then it's should return data between 2 date
So, what I'm doing is following : But it's showing me wrong result. How do I fix this ?
if(!empty($ad_datefrom)){
$getSearch .= "AND cd.created_date BETWEEN '$ad_datefrom' AND '$date' ";
}
if(!empty($ad_dateto)){
$getSearch .= "AND cd.created_date BETWEEN'$ad_dateto' AND '$date' ";
}
if(!empty($ad_datefrom) && !empty($ad_dateto)){
$getSearch .= "AND cd.created_date BETWEEN '$ad_datefrom' AND '$ad_dateto' ";
}
Note :
cd = contact_details Table.
created_date = created_date Column of contact_details Table.
$ad_datefrom = Date From field.
$ad_dateto = Date To Field.
$date = current date (m/d/y)
Thank You :)