Page 1 of 1

Completely Confused by Date Functions

Posted: Tue Jun 19, 2007 3:19 pm
by PastorHank
I have looked at several of the tutorials on using dates with PHP and MySql and I'll admit I am lost.

I have a date field in my database that is receiving the data from a desktop application and the data is being stored correctly on my server in the following format - 2007-06-18 - now I want to give users the ability to pull data by a range of dates.

Since php passes the data in strings I assume I must use a function of some sort, but I'm not sure which one or should I use a MySql function or a PHP function? Would someone please point me to a concise tutorial or a sample code that I could study?

Thank you

Posted: Tue Jun 19, 2007 3:27 pm
by volka
mysql converts strings of the format 'yyy-mm-dd' into dates as needed.
e.g.

Code: Select all

SELECT x,y,z FROM tbl WHERE datefiled between '2006-05-01' AND '2007-05-31'

Posted: Tue Jun 19, 2007 3:29 pm
by superdezign
Dates in MySQL are like strings. You can order them by alphabetical order (which also includes numbers).

Code: Select all

SELECT `column` FROM `table` WHERE `date` < '2007-06-19' ORDER BY `date` DESC;

Posted: Tue Jun 19, 2007 4:59 pm
by PastorHank
Thank you