Results 1 to 5 of 5

Thread: [RESOLVED] DateAdd Without Seconds

  1. #1

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    Resolved [RESOLVED] DateAdd Without Seconds

    Hi. I'm trying to compare 2 dates to see if they match up (e.g. 1/05/2011 and 1/05/2011) but I'm doing something wrong. So my question is, how do I get rid of the seconds in the code below?

    Code:
    y = DateAdd("d", -daypas + x, Now)
    This creates #2011-05-01 13:22:40# but I want it to be #2011-05-01#

    Formating it (d/mm/yyyy) creates a string (when I store it in a text file) and when I do this even though the two dates look the same (the other date is created by a calendar control) VB doesn't see a match. So any ideas? Thanks.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: DateAdd Without Seconds

    You could just 'extract' the dd/mm/yyyy component of Now
    Code:
    y = DateAdd("d", -daypas + x, Cdate(Format(Now, "dd/mm/yyyy")))

  3. #3

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    Re: DateAdd Without Seconds

    That works perfectly. Nice work Doogle.

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: [RESOLVED] DateAdd Without Seconds

    Why use Now then to struggle to remove the Time?

    If you want only the date without time,use Date() function instead of Now().

    Now = Date + Time

    Code:
    y = DateAdd("d", -daypas + x, Date)
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  5. #5

    Thread Starter
    Lively Member Yumby's Avatar
    Join Date
    Feb 2009
    Posts
    120

    Re: [RESOLVED] DateAdd Without Seconds

    Ok thanks for that anhn.

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