Completely Confused by Date Functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Completely Confused by Date Functions

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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'
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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;
PastorHank
Forum Contributor
Posts: 117
Joined: Sat Jun 03, 2006 7:58 am
Location: Texas Hill Country

Post by PastorHank »

Thank you
Post Reply