Unix Technical Forum

Concerned about dates [ extract vs <>= ]

This is a discussion on Concerned about dates [ extract vs <>= ] within the MySQL forums, part of the Database Server Software category; --> Hello, I am concerned as similiar queries, only changing the way I specify the dates, give different results. Query ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:29 AM
sveint
 
Posts: n/a
Default Concerned about dates [ extract vs <>= ]

Hello,

I am concerned as similiar queries, only changing the way I specify the
dates, give different results.

Query A would use EXTRACT, example:
EXTRACT(month FROM accountingdate)=' . $currentmonth . '

Query B would use <>=, example:
accountingdate>=' . $begindate . '

Now the odd thing is that I get different results, for a sum of sales
figures. A quick check of the actual sales summed up outside of the
database reveals that Query B gives the correct answer.

Now this is a major concern as I just Query A type syntax in some other
reports. Why doesn't it work correctly? Any links to more information
about extract? The manual information suggests that Query A should be
synonymous with Query B.

Thanks for any information

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:30 AM
Michael Austin
 
Posts: n/a
Default Re: Concerned about dates [ extract vs <>= ]

sveint wrote:

> Hello,
>
> I am concerned as similiar queries, only changing the way I specify the
> dates, give different results.
>
> Query A would use EXTRACT, example:
> EXTRACT(month FROM accountingdate)=' . $currentmonth . '
>
> Query B would use <>=, example:
> accountingdate>=' . $begindate . '
>
> Now the odd thing is that I get different results, for a sum of sales
> figures. A quick check of the actual sales summed up outside of the
> database reveals that Query B gives the correct answer.


To SQL, 1-nov-xxxx (all years) would be included in QueryA result, you must also
include the year.

> Now this is a major concern as I just Query A type syntax in some other
> reports. Why doesn't it work correctly? Any links to more information
> about extract? The manual information suggests that Query A should be
> synonymous with Query B.


No, they are not synonymous. See previous...

>
> Thanks for any information
>




--
Michael Austin
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:30 AM
Michael Austin
 
Posts: n/a
Default Re: Concerned about dates [ extract vs <>= ]

sveint wrote:

> Hello,
>
> I am concerned as similiar queries, only changing the way I specify the
> dates, give different results.
>
> Query A would use EXTRACT, example:
> EXTRACT(month FROM accountingdate)=' . $currentmonth . '
>
> Query B would use <>=, example:
> accountingdate>=' . $begindate . '
>
> Now the odd thing is that I get different results, for a sum of sales
> figures. A quick check of the actual sales summed up outside of the
> database reveals that Query B gives the correct answer.
>
> Now this is a major concern as I just Query A type syntax in some other
> reports. Why doesn't it work correctly? Any links to more information
> about extract? The manual information suggests that Query A should be
> synonymous with Query B.
>
> Thanks for any information
>

forgot to also mention that should you choose to use QueryB - I would also
include "AND accountingdate<' . $enddate . '" Make sure you know the exact
timeframe you are looking for.

--
Michael Austin.
DBA Consultant
Donations welcomed. Http://www.firstdbasource.com/donations.html

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:30 AM
sveint
 
Posts: n/a
Default Re: Concerned about dates [ extract vs <>= ]

I didn't show the full queries on purpose. I do know who to get date
ranges (extract month, year or between two dates). Extract still gives
wrong results.

I will write out an example to be clear, with the php removed, pure
SQL:

EXTRACT(month FROM accountingdate)=12 and EXTRACT(year FROM
accountingdate)=2005

vs

accountingdate>='2005-12-01' and accountingdate<='2005-12-31'

Logically the queries should be the same but the results differ (by
about 1%). So something somewhere goes wrong when I use EXTRACT.

Michael Austin wrote:
> sveint wrote:
>
> > Hello,
> >
> > I am concerned as similiar queries, only changing the way I specify the
> > dates, give different results.
> >
> > Query A would use EXTRACT, example:
> > EXTRACT(month FROM accountingdate)=' . $currentmonth . '
> >
> > Query B would use <>=, example:
> > accountingdate>=' . $begindate . '
> >
> > Now the odd thing is that I get different results, for a sum of sales
> > figures. A quick check of the actual sales summed up outside of the
> > database reveals that Query B gives the correct answer.
> >
> > Now this is a major concern as I just Query A type syntax in some other
> > reports. Why doesn't it work correctly? Any links to more information
> > about extract? The manual information suggests that Query A should be
> > synonymous with Query B.
> >
> > Thanks for any information
> >

> forgot to also mention that should you choose to use QueryB - I would also
> include "AND accountingdate<' . $enddate . '" Make sure you know the exact
> timeframe you are looking for.
>
> --
> Michael Austin.
> DBA Consultant
> Donations welcomed. Http://www.firstdbasource.com/donations.html
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:33 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com