Results 1 to 5 of 5
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    Access cant query by date when using getdate() in sql server

    i have database where i import data directly into the sql server using SSIS and i use a default for the import date using getdate()



    However, when i search for the date in access it wont find it unless I remove the time after the date.

    3/2/2022 10:44:37 AM - this is the way that sql server is bringing it in. If I search for 3/2/2022 it is not found

    If I delete the time so it is just date - 3/2/2022 - then searching by 3/2/2022 works.

    If I do a >3/1/2022 it works for both. My problem is I have a lot of queries that say [enter date] and so it would be best if I could just format the date on import to not have the time stamp.

    Is that possible?

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    GetDate() returns the time and date on SQL server.

    If you use

    Cast(Getdate() as Date)

    as the default value it should only give you a date with no time portion as the time part which access should treat as you want.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Ok, I was looking at something like that but didnt know if you could put it in as the sql default. I have updated my table and will test with tomorrows import.
    thanks

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Advise to not use dynamic parameter popup input because cannot validate. Reference control on form for input.

    See if this helps https://stackoverflow.com/questions/...ut-time-in-sql
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    For those interested. It did not work to put Cast(Getdate() as Date) in as the default for the table. SQL server accepted it but if you opened it backup again it was back to (getDate())
    So, since I am using SSIS I just import the data into a temporary table then put in a sql execute command of
    Update [mytable] Set ImportDate = Cast(getdate() as Date). This updates the date in the temp table to be what I need and then I used another sql execute command to append the data to the main table.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 05-19-2020, 11:55 AM
  2. Run SQL Server Parameter Query From Access VBA
    By jo15765 in forum Programming
    Replies: 0
    Last Post: 04-05-2017, 07:42 AM
  3. Replies: 6
    Last Post: 12-02-2016, 04:14 PM
  4. Replies: 2
    Last Post: 03-31-2012, 07:53 AM
  5. Convert query sql server for Access
    By webtony in forum Queries
    Replies: 0
    Last Post: 06-23-2009, 02:46 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
  •  
Other Forums: Microsoft Office Forums