Re: something about dates in mysql
| From: | Webforlaget.dk | Date: | Thu, 03 Mar 2011 21:20:07 +0000 |
| Subject: | Re: something about dates in mysql | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-311650@lists.php.net to get a copy of this message | ||
In this case $mth, $day, $year is userinput that needs to be validated before use. thanks for all help, the quotes proved helpfull
Med venlig hilsen
Rolf Brejner
Web-forlaget.dk
----- Original Message ----- From: "Richard Quadling" <rquadling@gmail.com>
To: "Alex" <niksoft@gmail.com>
Cc: <php-general@lists.php.net>
Sent: Thursday, March 03, 2011 2:13 PM
Subject: Re: [PHP] something about dates in mysql
On 3 March 2011 12:33, Alex <niksoft@gmail.com> wrote:
Just a correction, dates in mysql are not strings by any means, they are stored in 3 bytes (date and time or 8 bytes for datetime) and that's nowhere enough for a string, however the representation of the date is a formatted string, so for all intents and purposes any comparison to a date field should be using quotes like mentioned already. -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. Nathan Rixham <nrixham@gmail.com> wrote: Richard Quadling wrote: > On 3 March 2011 10:09, Webforlaget.dk <info@web-forlaget.dk> wrote: >> I need help to know Why this dont work ?I didn't intend to suggest that dates in mysql were STORED as strings, just that in the SQL Statement they were treated as strings. -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php$sql = "SELECT id,case,startdate,enddate FROM table WHERE >_____________________________________________ $thisdate =date("Y-m-d",mktime(0,0,0,$mth, $day, $year)); >> >> $sql = "SELECT id,case,startdate,enddate FROM table WHERE startdate<=$thisdate AND enddate>=$thisdate ORDER BY startdate"; >>The result should be an array whith open cases at $thisdate, but nothing appear. >> >> Is it something about dates in mysql ? >> >> Thanks for any advice. >> >> Best regards, >> >> Venlige hilsner >>_____________________________________________in the quotes as they > are strings and not integers. > > So, try ...Rolf Brejner > > I think that dates in SQL statements need to beI'm surprised you don't get an error.... > > Ah. As it stands,startdate<='$thisdate' AND enddate>='$thisdate' ORDER BY startdate";the SQL is something like ... > > WHERE startdate <= 2010 - 3 - 3 > > So, probably the actual test that is being executed is .... > > WHERE startdate <= 2004 > > Which, for a date stamp will never return anything sensible. yes, and remember the DATE and FROM_UNIXTIME mysql functions too. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php