List:General Discussion« Previous MessageNext Message »
From:Jim Faucette Date:May 25 1999 7:47pm
Subject:Re: Dates querying Mysql
View as plain text  
Vivek Khera wrote:
> 
> >>>>> "CMC" == Claudia M Castaneda <claudia@stripped>
> writes:
> 
> CMC> Well, it worked!!
> 
> CMC> Now, if you would be kind enough to explain us what is in a +0???
> 
> For the same reason that
> 
>  select obs_id, obs_URI, obs_source, beg_date, beg_time from
>  observation where beg_date between '1999-01-20' and '1999-05-30';
> 
> will work.  The automagic type conversion from strings to numbers in
> MySQL seems to fail in this instance when comparing a string type to
> numbers with "BETWEEN".
> 
> By adding the +0, you explicitly converted the date to a number type.
> In my example, I made the values for the BETWEEN into strings, which
> are treated nicely as DATEs.
> 
> I don't know which is faster, though.
> 

Since MySQL stores dates as numbers (long longs?), but returns them as
strings the ntoa conversion is still needed. However, +0 may save a
string formatting step.

(Awaiting Monty's thoughts :)

  jim...

Claudia, here some examples of +0 forcing results to ints:
mysql> select "test";
+------+
| test |
+------+
| test |
+------+
1 row in set (0.00 sec)

mysql> select "test"+0;
+----------+
| "test"+0 |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

mysql> select "100test"+0;
+-------------+
| "100test"+0 |
+-------------+
|         100 |
+-------------+
1 row in set (0.00 sec)

mysql> select "100.001test"+0;
+-----------------+
| "100.001test"+0 |
+-----------------+
|             100 |
+-----------------+
1 row in set (0.01 sec)
Thread
Dates querying MysqlClaudia M. Castaneda24 May
  • Re: Dates querying MysqlGraeme B. Davis25 May
  • Re: Dates querying MysqlChristian Mack25 May
    • Re: Dates querying MysqlClaudia M. Castaneda25 May
      • Re: Dates querying MysqlJim Faucette25 May
        • Re: Dates querying MysqlClaudia M. Castaneda25 May
          • Re: Dates querying MysqlVivek Khera25 May
        • Re: Dates querying MysqlJim Faucette25 May
          • Re: Dates querying MysqlMichael Widenius2 Jun
            • Re: Dates querying MysqlVivek Khera2 Jun
              • Re: Dates querying MysqlMichael Widenius3 Jun
Re: Dates querying MysqlVivek Khera2 Jun