Results 1 to 9 of 9

Thread: [RESOLVED] DateAdd: Crossing Midnight

  1. #1

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Resolved [RESOLVED] DateAdd: Crossing Midnight

    Can anyone explain why this happens and how to get around it:

    This code:
    VB Code:
    1. DateAdd("s", 1, #12:59:59 PM#)
    Returns this:
    1:00:00 PM

    Not this:
    00:00:00 AM

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: DateAdd: Crossing Midnight

    That's what it should be doing......

  3. #3
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: DateAdd: Crossing Midnight

    You're just past noon.

    #12:59:59 PM# is 59 minutes and 59 seconds past noon.
    Or 1 second to 1 PM.

    Try:
    VB Code:
    1. Print #12:30 AM#
    2. Print #12:30 PM#

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: DateAdd: Crossing Midnight

    Try DateAdd("s", 1, #11:59:59 PM#)

    I don't know about you, but I get long ago and far away.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  5. #5
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: DateAdd: Crossing Midnight

    If you change it to 11:59:59 AM then it goes to 12:00:00 it will never go to 0:00:00

  6. #6

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Re: DateAdd: Crossing Midnight

    You're right about 12:59PM to 1 PM. My goof.

    However,

    VB Code:
    1. DateAdd("s", 1, #11:59:59 PM#)
    returns:

    12/31/1899

    Not exactly what I expected (which is 12:00:00 AM). I'm trying to match time on a web server by reading a web page, parsing the time out of the HTML, then keeping track of the server's time by adding 1 second every, well, second.

    So this is a problem.

  7. #7

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Re: DateAdd: Crossing Midnight

    You're right about 12:59PM to 1 PM. My goof.

    However, as A142 points out:

    VB Code:
    1. DateAdd("s", 1, #11:59:59 PM#)
    returns:

    12/31/1899

    Not exactly what I expected (which is 12:00:00 AM). I'm trying to match time on a web server by reading a web page, parsing the time out of the HTML, then keeping track of the server's time by adding 1 second.

    So this is a problem.

  8. #8
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    324

    Re: DateAdd: Crossing Midnight

    I had the same problem before.

    Either add a date to your time string i.e.

    VB Code:
    1. DateAdd("s", 1, #18/02/2007 11:59:59 PM#)

    or

    use the TimeValue function for your result i.e.

    VB Code:
    1. MsgBox TimeValue(DateAdd("s", 1, #11:59:59 PM#))

  9. #9

    Thread Starter
    Hyperactive Member rjbudz's Avatar
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    262

    Re: DateAdd: Crossing Midnight

    Excellent. I think that'll do it. Thanks!

Posting Permissions

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



Click Here to Expand Forum to Full Width