Forum Moderators: coopster
I have a simple problem, I tried it but getting error, still trying to solve but thought will get the help from some experts too.
Database(mysql) date format :yyyy-mm-dd 00:00:00
client site query date is : dd/mm/yyyy
I have seprated the client side date into different portions like (dd) and (mm) and (yyyy). I can get them
My problems
------------------
(1) I want to query between two dates say 21/04/2004 to 23/04/2004 , how to do that?
(2) I want yyyy-mm-dd 00:00:00 , to seprate month , date , year , time from this format using php, how can I do that, I know its easy but I am not an expert on php and mysql.
I am using the following query, but the problem is with the date format ,
$sql1="select * from TblUsers1,TblUserInfo1 where TblUserInfo1.FldUserID=TblUsers1.FldUserID and (TblUsers1.FldDateSubscribed BETWEEN '$StartDate' AND '$EndDate')";
HELP HELP HELP
Thank
Aji
There might be a better way, but if you aren't sure of the date format, I use a double conversion. strtodate() gives you a timestamp from a string date in a wide variety of formats and date() gives you formated output from a timestamp.
$date = 21/04/2004;
$other_date = 23/04/2004;
$tstamp = strtodate($date);
$integer_day_of_month = date('d', $tstamp);
$four_digit_year = date('Y', $tstamp);
etc.
$query_date1 = date('Y-m-d', strtodate($date));
$query_date2 = date('Y-m-d', strtodate($other_date));
$query = "SELECT field1 FROM table1 WHERE date > '$query_date1' AND date < '$query_date2'";
Note that this is non-inclusive of date1 and date2, use <= >= for inclusive searching.