PDA

View Full Version : A php- mysql problem- date formats problem


Aji
22-05-2004, 04:53/04:53AM
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

WebSavvy
22-05-2004, 06:04/06:04AM
$qResult=mysql_query("SELECT TO_DAYS(MAX(StartDate))-TO_DAYS(MIN(EndDate)) as mydatediff FROM TblUsers1,TblUserInfo1 WHERE 1 AND TblUserInfo1.FldUserID='TblUsers1.FldUserID'");
You can also create variables to work with using mktime() (http://us3.php.net/date)

Aji
22-05-2004, 08:15/08:15AM
Thanks but here the problem is date format, how to convert dd/mm/yyyy to yyyy:mm:dd 00:00:00 and then query.

Thanks again
Aji

WebSavvy
22-05-2004, 09:39/09:39AM
Does your db field actually contain a timestamp or some info for time?

WebSavvy
24-05-2004, 03:12/03:12AM
Aji, this code should work to do what you're trying to accomplish.

date( "F j, Y g:ia T", $row["StartDate"] )
date( "F j, Y g:ia T", $row["EndDate"] )

You can change the date() formats to anything you'd like to use.

a prints: am or pm
A prints: AM or PM
h prints: 12-hour format (01-12)
H prints: 24-hour format (00-23)
g prints: 12-hour format w/o leading zero (1-12)
G prints: 24-hour format w/o leading zero (0-23)
i prints: minutes (00-59)
s prints: seconds (00-59)
Z prints: time zone offset in seconds (-43200 to 43200)
d prints: day of the month, two digits (01-31)
j prints: day of the month, two digits w/o leading zero (1-31)
F prints: month, long text (January - December)
m prints: month, two digits (01-12)
n prints: month, two digits w/o leading zero (1-12)
Y prints: year, four digit (0000)
y prints: year, two digits (00)

Aji
24-05-2004, 12:07/12:07PM
That was useful, I have done it in a different way, will try this also .

Thanks
Aji