adding hours + minutes with dateadd function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CVAR
    New Member
    • Jun 2016
    • 21

    adding hours + minutes with dateadd function

    This is my first database in Access and I've been able to format and add date under 60 mins using the dateadd function... but I can't add dates OVER 1 hour like, 1:20, 1:25...etc...it just says type mismatch, and I can't find any solution to this problem, neither Microsoft or the web gives me any example of the Dateadd function when it comes to add hours + minutes ....

    Code:
    DateAdd("n", d, l)
    Code:
    DateAdd("H:N", d, l)
    "n" = format any minute amount from 0 to 59 depending the case

    "H:N" = format hours from 1 to 24 and from 0 to 59 minutes depending the case

    d = 1:20(one hour and twenty minutes)(datepa rt) or 0:20(twenty minutes)(datepa rt)

    l = The "actual" time (8:00 AM) (current time)



    ex. Dateadd("n", "0:20", 8:00 AM)
    Already did the example above (d = 0:20) in the program , It returns me 8:20 AM without a problem, but. the next one...

    ex. Dateadd("H:N"," 1:20", 8:00 AM)

    The above example should return "9:20 AM" but instead it returns syntax error, If I replace the "h:nn" to "n" it accepts the entry but assigns only "20" minutes, is this the correct way to format this?
    Last edited by CVAR; Jun 29 '16, 04:11 AM. Reason: fixed syntax
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    If you read the function description you should understand:
    DateAdd Function - Syntax:
    DateAdd ( interval, number, date ) (read me)


    The only valid Interval settings are as given in the table in the above link. The string you are attempting to use is not one that is given; thus, the syntax error.

    You must convert your desired interval to add (in this case 1 hour and 20 minutes) to one of the provided intervals (i.e. 80 minutes) and then execute the function.
    DateAdd ("n",80,#20:00# )

    -z
    Last edited by zmbd; Jun 29 '16, 06:09 AM.

    Comment

    Working...