Querying Access Database Using Dates

Results 1 to 2 of 2

Thread: Querying Access Database Using Dates

  1. #1
    Join Date
    Dec 1969

    Default Querying Access Database Using Dates

    Can&#039t query an access db using dates. I want to search for all records that are 14 days old:<BR>dim myDate<BR>myDate=Now()<BR>myDate=Now()<BR>myDate=F ormatDateTime(gek(2),2)<BR>myDate=CDate(gek(2)) <BR>myDate=gek(2)-14<BR>myDate=CDate(gek(2))<BR>&#039This gives me the date 14 days ago but when I query the database: (field type is Long Date)<BR>SELECT * FROM tblMine WHERE updDate=CDate(" & gek(2) & ")<BR>I get nothing but also tried:<BR>SELECT * FROM tblMine WHERE updDate=" & gek(2) & "<BR>Nothing. I also tried using the SQL DateDiff Function:<BR>SELECT * FROM tblMine WHERE DateDiff(DAY,updDate,GETDATE())=14<BR>But Access keeps kicking an error saying GETDATE was an undefined function - I&#039ve used in in SQL<BR><BR>There are records that match the query - what is the proper format, please?<BR>Thanks

  2. #2
    David Milner Guest

    Default RE: Querying Access Database Using Dates

    In Access, you must wrap dates with # characters.<BR><BR>Example:<BR>SELECT * FROM tblMine WHERE updDate=CDate(#" & gek(2) & "#)"<BR>

Posting Permissions

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