solon Posted November 2, 2008 Share Posted November 2, 2008 Morning guys, I have a problem in an sql query with the date validation! I have an sql query that asks for: SELECT * FROM `table` WHERE `date`>= '$date' Lets say that $date='02.10.08' which is todays date using $today = date("d.m.y"); I get all the rows that their date is greater only in the first part of the date value which is '02' from 02.11.08! Is there a way to check all the date? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/131068-php-mysql-date-validation-problem/ Share on other sites More sharing options...
AndyB Posted November 2, 2008 Share Posted November 2, 2008 Best guess - you're using a varchar field for the date in the database. Much better - use the mysql date format field, with dates in the ISO yyyy-mm-dd format (so you can properly sort, etc. etc.) and display dates in whatever tribal format you prefer. Link to comment https://forums.phpfreaks.com/topic/131068-php-mysql-date-validation-problem/#findComment-680485 Share on other sites More sharing options...
solon Posted November 2, 2008 Author Share Posted November 2, 2008 Yes i do use VARCHAR but its only because i dont know how to display the date in a format dd.mm.yy if i used the date format field! Can you please give me some guidelines how to do it? Link to comment https://forums.phpfreaks.com/topic/131068-php-mysql-date-validation-problem/#findComment-680486 Share on other sites More sharing options...
Flames Posted November 2, 2008 Share Posted November 2, 2008 $sql = "SELECT *, DATE_FORMAT('he_name_of_your_date_field', '%d %m %y') AS date2 FROM table WHERE id = '1"; $query = mysql_query($sql); $result = mysql_fetch_assoc($query); $date = $result['date2']; echo $date; for more on the date operators goto http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format Link to comment https://forums.phpfreaks.com/topic/131068-php-mysql-date-validation-problem/#findComment-680494 Share on other sites More sharing options...
solon Posted November 2, 2008 Author Share Posted November 2, 2008 Thank you very much Link to comment https://forums.phpfreaks.com/topic/131068-php-mysql-date-validation-problem/#findComment-680696 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.