Results 1 to 6 of 6

Thread: Format and compare time

  1. #1

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Format and compare time

    I have the time in the format of 11:25pm

    Is there a quick function that can compare the string above, with the current time and check if its before now, now, or after now?

    I can do it the long winded way by extracting the hours,mins etc and comparing but I was hoping there would be a function already.

    Cheers
    Chris

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: Format and compare time

    You can use DateTime.Compare method.

    .Compare returns an integer value: -1 for less than, 0 for equal, and 1 for greater than if you just want a quick check rather than specific amounts of minutes or hours.
    Last edited by stimbo; Jan 25th, 2007 at 11:30 AM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Format and compare time

    Scroll down to Post #14 in this thread.

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Format and compare time

    There could be an issue is 11:27 pm before or after your time? What if that time (11:27 pm) was last night of 3 days ago was that before the current time?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Format and compare time

    the day doesnt matter, I only want to know if the current time is prior, equal, or beyond the input string in the format of "1.35pm" or "10.50am". I'll try the suggesstions and wirte back,

    Cheers
    Chris

  6. #6

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Format and compare time

    thanks that compare function was just what I needed.

    The second thing I need is a function to convert this time format:

    11.50am or 3.05pm or 9.10am

    to this:
    11:50 or 15:05 or 9:10

    Like i said it can be done by extracting the mins, hours, pm and am, but I was hoping there would be a function like Format() that could do it
    Chris

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