Re: Date comparison issue




"javelin" <google.1.jvmail@xxxxxxxxxxxxxxx> wrote in message
news:1170177671.179606.263210@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|I have a table with dates stored in a text field (designed before my
| time, I'm just stuck with the headaches). When I run the following
| query:
|
| SELECT DATE_FORMAT(datefield,'%m/%d/%Y') FROM computers where
| datefield>'1/1/2000' and DATE_FORMAT(datefield,'%m/%d/%Y') <
| '12/1/2006' group by datefield;
|
| I get 22 records. However, when I use the following query (which I
| think is better), I lose some of the records that match the criteria,
| as when I run the first one:
|
| SELECT DATE_FORMAT(datefield,'%m/%d/%Y') FROM computers where
| DATE_FORMAT(datefield,'%m/%d/%Y') >'1/1/2000' and
| DATE_FORMAT(datefield,'%m/%d/%Y') < '12/1/2006' group by datefield;
|
| Any clues as to why? Any way to convert the date for accurate
| comparisons????

don't use date_format. otherwise, you are comparing a string to a string
rather than a date to a date that mysql translates/converts from a string
(ex. '1/1/2006').


.



Relevant Pages

  • Date comparison issue
    ... I'm just stuck with the headaches). ... SELECT DATE_FORMATFROM computers where ... when I use the following query (which I ...
    (alt.php)
  • Re: Problems with Delete Command
    ... The SQL could get fairly messy if you need to construct it in code, ... ContactID, and WebComID, and create your on-the-fly SQL on that saved query, ... to find the list of ContactIDs from the junction table, ... This is a style/readability thing: if you are going to use string ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Need help with Code Please!!!
    ... the actual string that gets built at the end of the SQ1 build process. ... The message says Syntax error in query expression ... Dim rs As Recordset 'object ref to qryCompany\USFNumber ...
    (microsoft.public.access.formscoding)
  • Re: Need help with Code Please!!!
    ... putting the query SQL itself in here maybe it will help you understand what I ... the actual string that gets built at the end of the SQ1 build process. ... Dim rs As Recordset 'object ref to qryCompany\USFNumber ... Dim qd As QueryDef 'object ref to query item ...
    (microsoft.public.access.formscoding)
  • Re: Need help with Code Please!!!
    ... the actual string that gets built at the end of the SQ1 build process. ... The message says Syntax error in query expression ... Dim rs As Recordset 'object ref to qryCompany\USFNumber ...
    (microsoft.public.access.formscoding)