Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2002
    Posts
    42

    Unanswered: Date in Select Count Statement - US or Eng

    I have a form with a text box:txtApptDate

    I have a select statement that reads:

    strsql = "SELECT COUNT (*) FROM tblothernotes " & _
    "WHERE appt_date = #" & Me.TxtApptDate & "#"


    Set rec = CurrentDb().OpenRecordset(strsql)
    If Not rec.EOF Then
    If rec(0) > 0 Then

    If the date reads say 4/12/2007 I get zero records.(There ARE 4/12/2007 dates in the table)
    If the date reads 13/12/2007 I get the correct record count.
    There appears to be a conflict with the day and the month - cannot decide whether US date or English date.
    How do I resolve this?

    Thanks

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6

  3. #3
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    This is what I often do:

    Code:
    WHERE appt_date = #" & Format(Me.TxtApptDate,"d mmm yyyy") & "#"
    Seems to resolve the DMY/MDY conflict issue.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Like Startrekker, personally I prefer to use mmm as the date format, except for those very odd occasions where space may be critical, to me it looks nicer but the real reason is that it always avoids confusions over dates. it doesn't matter if the month precedes the day (US format) or follows the day (most of the world format)...... its immediately clear to all what the date actually is with minimum fuss.

  5. #5
    Join Date
    Dec 2002
    Posts
    42
    Thanks for that

  6. #6
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8
    my rule of thumb is

    When i build a SQL STATEMENT IN CODE date must be in usa format

    so I have this function

    [code]
    function USAdate(vdate)
    USAdate = month(vdate) & "/" & day(vdate) & "/" & Year(vdate)
    end function
    [code]


    WHERE appt_date = #" & USADate(Me.TxtApptDate) & "#"
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

Posting Permissions

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