dbTalk Databases Forums  

'2010-07-01 00:00:00' vs '2010-07-01'

comp.databases.mysql comp.databases.mysql


Discuss '2010-07-01 00:00:00' vs '2010-07-01' in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
yawnmoth
 
Posts: n/a

Default '2010-07-01 00:00:00' vs '2010-07-01' - 07-06-2010 , 05:04 PM






i have two SQL queries:

SELECT column_name FROM table_name WHERE column_name >= '2010-07-01
00:00:00'
SELECT column_name FROM table_name WHERE column_name >= '2010-07-01'

the former returns dates starting at 2010-07-02 whereas the latter
returns dates starting at 2010-07-01. my question is... why aren't
they doing the same thing? if anything i would have expected the
second one to be the one that wasn't returning 2010-07-02 - not the
first one.

Reply With Quote
  #2  
Old   
The Natural Philosopher
 
Posts: n/a

Default Re: '2010-07-01 00:00:00' vs '2010-07-01' - 07-06-2010 , 05:26 PM






yawnmoth wrote:
Quote:
i have two SQL queries:

SELECT column_name FROM table_name WHERE column_name >= '2010-07-01
00:00:00'
SELECT column_name FROM table_name WHERE column_name >= '2010-07-01'

the former returns dates starting at 2010-07-02 whereas the latter
returns dates starting at 2010-07-01. my question is... why aren't
they doing the same thing? if anything i would have expected the
second one to be the one that wasn't returning 2010-07-02 - not the
first one.
Anyone who compares a date in textual format using an arithmetical
statement, deserves all the confusion he gets IMHO :-)

Reply With Quote
  #3  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: '2010-07-01 00:00:00' vs '2010-07-01' - 07-06-2010 , 05:37 PM



On 2010-07-06 23:04, yawnmoth wrote:
Quote:
i have two SQL queries:

SELECT column_name FROM table_name WHERE column_name >= '2010-07-01
00:00:00'
SELECT column_name FROM table_name WHERE column_name >= '2010-07-01'

the former returns dates starting at 2010-07-02 whereas the latter
returns dates starting at 2010-07-01. my question is... why aren't
they doing the same thing? if anything i would have expected the
second one to be the one that wasn't returning 2010-07-02 - not the
first one.
What type is column_name and what version/engine are you using? Assuming
date and innodb your example works fine with:

mysql> select @@version;
+-----------+
Quote:
@@version |
+-----------+
5.1.47 |
+-----------+

mysql> create table T (c date not null) engine = innodb;
Query OK, 0 rows affected (0.07 sec)

mysql> insert into T values ('2010-07-01'),('2010-07-02');
Query OK, 2 rows affected (0.04 sec)
Records: 2 Duplicates: 0 Warnings: 0

mysql> select c from T where c >= '2010-07-01 00:00:00';
+------------+
Quote:
c |
+------------+
2010-07-01 |
2010-07-02 |
+------------+
2 rows in set (0.02 sec)

mysql> select c from T where c >= '2010-07-01';
+------------+
Quote:
c |
+------------+
2010-07-01 |
2010-07-02 |
+------------+
2 rows in set (0.00 sec)


/Lennart

Reply With Quote
  #4  
Old   
Peter H. Coffin
 
Posts: n/a

Default Re: '2010-07-01 00:00:00' vs '2010-07-01' - 07-07-2010 , 10:25 PM



On Tue, 6 Jul 2010 14:04:33 -0700 (PDT), yawnmoth wrote:
Quote:
i have two SQL queries:

SELECT column_name FROM table_name WHERE column_name >= '2010-07-01
00:00:00'
SELECT column_name FROM table_name WHERE column_name >= '2010-07-01'

the former returns dates starting at 2010-07-02 whereas the latter
returns dates starting at 2010-07-01. my question is... why aren't
they doing the same thing? if anything i would have expected the
second one to be the one that wasn't returning 2010-07-02 - not the
first one.
But it's the first all day! It can't be greater than the first until
it's not the first anymore. What day would that be?

--
30. All bumbling conjurers, clumsy squires, no-talent bards, and
cowardly thieves in the land will be preemptively put to death. My
foes will surely give up and abandon their quest if they have no
source of comic relief. --Peter Anspach's Evil Overlord list

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.