CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: time formatting

  1. #1
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    2,222

    time formatting

    I am formatting a string like so:

    .Column("StartTime").Value = Format(clsDateConvert.sShortTime, "hh:mm:ss AMPM")

    This works perfectly most of the time, but if the sShortTime value is 24:00, it will not format the value correctly.

    i.e.
    for "23:00" it will convert to "11:30 PM" properly
    but for "24:00" it will remain as "24:00" instead of converting to "12:00 PM"

    Why does this happen?

  2. #2
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: time formatting

    2300 (eleven oclock) gets converted to 1130PM (half past eleven)?
    2400 doesnt get converted to 1200PM (why would it? surely 2400 is 12 AM ?)

    sounds like the conversion routine is screwed.. any convertor that adds half an hour when converting 2300, ought to be dumped..
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  3. #3
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    2,222

    Re: time formatting

    2400 doesnt get converted to 1200PM (why would it? surely 2400 is 12 AM ?)
    Right, reguardless, it is not converted to 1200AM either. Apparently the Format function does not work properly? Do I need to write my own code to handle this particular case?

    thanks

  4. #4
    Join Date
    Dec 2001
    Posts
    6,332

    Re: time formatting

    There are only 24 hours in a day. Thus 23:59 is as far as it goes, and 24:00 is an invalid time.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  5. #5
    Join Date
    Jun 2001
    Location
    Michigan
    Posts
    2,222

    Re: time formatting

    Thankyou.

    I just learned our system allows 24:00 as a valid time

    10.19.04 & 24:00:00
    is the same as
    10.20.04 at 00:00:00

    I'll have to code this special case we use.

  6. #6
    Join Date
    Dec 2001
    Posts
    6,332

    Re: time formatting

    Actually, I believe "n" should be used for minutes, as in "hh:nn:ss AMPM", although both do seem to work in a quick test I just tried ("m" is for months). Anyway, the IsDate() function shows "24:00" as invalid, so you should probably use that to prevent formatting errors.

    Using the following formula could also help: MyHour = TheHour Mod 24. This would require parsing out the hour, but you cannot use Hour(TheTime) on an invalid time.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

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

Featured