Forum Moderators: coopster

Message Too Old, No Replies

A php- mysql problem- date formats problem

help help help , thanks thanks thanks

         

AjiNIMC

7:56 am on May 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

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

ergophobe

3:58 pm on May 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not exactly sure what you want, but this should get you started

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.

AjiNIMC

12:59 pm on May 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks I have solved the problem in a different way, thanks again

Aji