Jump to content

php mysql DATE validation problem


solon

Recommended Posts

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

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.

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.