Results 1 to 4 of 4
  1. #1
    behnam is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    72

    Date add function not working in some cases.

    Hi, when i use the date add function to subtract three hours from a long type time filed (ie. 10:30:22 PM) its works but dosent work when the time is 2:59:59 AM and under because when i subtract 3 hours it dosent go to 11:59:59 PM like it should instead, i get gibberish like 10/31/1899. the code is



    Code:
    Text436 = DateAdd("h", -3, [start time1])
    can anyone help me fix this issue, thanks.

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Are you just getting

    10/31/1899

    or

    10/31/1899 11:59:59 PM

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    If the data that is in [start time1] is ONLY the time, and no date part, that is the cause of the problem. Here is what I did in the immediate pane, and you can see that I replicated the problem:

    x=#2:59:59 AM#
    ?x
    2:59:59 AM
    ?dateadd("h",-3,x)
    29/12/1899 11:59:59 PM

    The time part is correct, but the date part is wrong because there wasn't one there to begin with.

    In order to get what you want, you will have to include the date in [start time1], even if you don't display it.

    John

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As John said, Access defaults to 29/12/1899 (or 12/29/1899, in this country) when the date portion is missing. If all you're really only interested is the time, you could use

    Me.Text416 = Format(DateAdd("h", -3, [start time1]), "hh:mm:ss am/pm")

    And it will only return/display the Time portion.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 3
    Last Post: 01-29-2013, 04:34 AM
  2. Max Function Not Working With Date
    By cec in forum Forms
    Replies: 4
    Last Post: 11-14-2012, 06:00 PM
  3. NZ() function not working?
    By EvanRosenlieb in forum Programming
    Replies: 6
    Last Post: 12-22-2011, 05:37 PM
  4. OrderBy Not working for select few cases
    By walter189 in forum Programming
    Replies: 2
    Last Post: 08-19-2011, 05:53 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