CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    1,900

    Resolved - SQL Statement for Selecting Date Range

    I have a TEXT field which contains a Date in a Table in an ACCESS Database

    I want to select records from the table using an SQL Statement

    Code:
    eg, Select * from Table where DateField between #01/01/2004# and #31/07/2004#
    The problem is that the DateField is treated as a text literal rather than a date, so in reality, every date on file is selected

    Is there a trick to make the SQL Statement understand that the text field is in fact a date field and therefore do a date comparison rather than a text comparison ?

    eg, Is there a way I can invert the text field (withing the SQL Statement) so I am comparing with a value like 20040525

    RESOLUTION

    You need to add the cdate function to the string

    Code:
    eg, Select * from Table where cdate(DateField) between #01/01/2004# and #31/07/2004#

    Thanks
    Last edited by George1111; March 25th, 2007 at 08:59 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured