Results 1 to 26 of 26

Thread: Incorrect Time Display

  1. #1

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Incorrect Time Display

    Code:
    Dim TestTime As DateTime
    
    TestTime = Convert.ToDateTime("12:00:00")
    
    Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
    
    Debug.WriteLine(TestString & " <<--Error")
    debug output - a correct statement

    12:00:00 PM <<--Error




    0002, is the lonliest number... apologies to Three Dog Night
    Last edited by dbasnett; Mar 5th, 2008 at 04:42 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Incorrect Time Display

    what output are you expecting?

  3. #3

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Incorrect Time Display

    The correct one, how about you?

    0002, is the lonliest number... apologies to Three Dog Night
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Incorrect Time Display

    well that is what I am asking you, what do you think the correct output should be

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Incorrect Time Display

    and please don't say it should be AM...

  6. #6
    Member
    Join Date
    Mar 2008
    Posts
    33

    Re: Incorrect Time Display

    What are you looking for as far as the output is concerned? I ran this code and got the correct result.

    The Convert.ToDateTime() function is using a 24-Hour clock. So, if you want 12:00 AM the code would be:

    Code:
    Dim TestTime As DateTime
    
    TestTime = Convert.ToDateTime("00:00:00")
    
    Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
    
    Debug.WriteLine(TestString & " <<--Error")
    Or, you can also write it as:

    Code:
    Dim TestTime As DateTime
    
    TestTime = Convert.ToDateTime("12:00:00 AM")
    
    Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
    
    Debug.WriteLine(TestString & " <<--Error")
    Either of these examples will give you a result of 12:00 AM

  7. #7

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Incorrect Time Display

    and please I won't. To tell the truth it should say error here
    TestTime = Convert.ToDateTime("12:00:00")

    Since there was a discussion about whether 0002 was number or not, I thought I would bring this up.

    Simply put, 12AM / 12PM and relatives (12:00:00 AM / 12:00:00 PM) are nonsense. I acknowledge that a lot of people know what is meant by that, but I am not one of them.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  8. #8
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Incorrect Time Display

    I don't understand the problem. Check your computers regional settings:
    Code:
    LongTime
     vbLongTime
     Displays a time using the long-time format specified in your computer's regional settings
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Incorrect Time Display

    yeah, as VisualAd says, its all based on your PC settings...

    Lots of countries use , instead of . with numbers

    1,000,000.50
    1.000.000,50

    Or dates are written

    03/05/2008
    05/03/2008

    If you don't know what culture you are using, then it is impossible to know if the date is march 5th, or may 3rd. However based on the culture, there are rules that govern the correct order of things.

  10. #10

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Incorrect Time Display

    Google -->>> noon midnight PM AM
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Incorrect Time Display

    Quote Originally Posted by LloydAZ
    What are you looking for as far as the output is concerned? I ran this code and got the correct result.

    The Convert.ToDateTime() function is using a 24-Hour clock. So, if you want 12:00 AM the code would be:

    Code:
    Dim TestTime As DateTime
    
    TestTime = Convert.ToDateTime("00:00:00")
    
    Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
    
    Debug.WriteLine(TestString & " <<--Error")
    Or, you can also write it as:

    Code:
    Dim TestTime As DateTime
    
    TestTime = Convert.ToDateTime("12:00:00 AM")
    
    Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
    
    Debug.WriteLine(TestString & " <<--Error")
    Either of these examples will give you a result of 12:00 AM
    google, google, google. --->> noon midnight PM AM


    You said "I ran this code and got the correct result." I think you ran the code and got an answer you expected.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Incorrect Time Display

    This thread really confuses me. Are we speaking in riddles?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  13. #13

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Incorrect Time Display

    Quote Originally Posted by kleinma
    yeah, as VisualAd says, its all based on your PC settings...

    Lots of countries use , instead of . with numbers

    1,000,000.50
    1.000.000,50

    Or dates are written

    03/05/2008
    05/03/2008

    If you don't know what culture you are using, then it is impossible to know if the date is march 5th, or may 3rd. However based on the culture, there are rules that govern the correct order of things.
    But don't I have a right for the result to be correct for my regional settings.

    Like I said, in the spirit of 002, I brought this up. I don't deal with this. I always use military time (wonder why they do) and get clarifiaction if we are going to meet at 12AM / 12PM. It is just sad that Microsoft can't tell time.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  14. #14

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Incorrect Time Display

    Quote Originally Posted by Atheist
    This thread really confuses me. Are we speaking in riddles?
    I was doing a 002. If you want to know just google > noon midnight PM AM
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  15. #15
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Incorrect Time Display

    honestly I still fail to see what you are saying here....

    You have yet to claim what you THINK the output should be.... we all think there is no issue.

    So if you think there actually is an issue, you need to say "The output should be this: x, and this is why, x"

  16. #16
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Incorrect Time Display

    This discussion is also happening in another thread (where there was also a lack of explanation of the 'problem'): http://www.vbforums.com/showthread.php?t=512121


    dbasnett is referring to the fact that while there is a common understanding of what 12:00:00 AM means, to be extremely picky it is technically not valid (it should be "midnight"), but 12:00:01 AM is valid for a second later.

  17. #17

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Incorrect Time Display

    Either of these would be better, but not definitive.
    Code:
    Dim TestTime As DateTime
    
    TestTime = Convert.ToDateTime("12:00:00 Noon")
    
    Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
    
    Debug.WriteLine(TestString)
    
    debug output -> 12:00:00 Noon
    
    or 
    
    Dim TestTime As DateTime
    
    TestTime = Convert.ToDateTime("12:00:00 Midnight")
    
    Dim TestString As String = FormatDateTime(TestTime, DateFormat.LongTime)
    
    Debug.WriteLine(TestString)
    
    debug output -> 12:00:00 Midnight
    If I say lets meet at 12PM March 5th, when do I want to meet? At the boundary between march 5 - 6 or 4 - 5?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  18. #18
    Member
    Join Date
    Mar 2008
    Posts
    33

    Re: Incorrect Time Display

    I googled like you requested.

    In theory it makes sense. But think of it this way as well:

    1 nanosecond past midnight would make it AM and one nanosecond past noon would make it PM.

    From a programming perspective, I would have to say that the answer that the application gives is correct. Trying to determine that the precise moment in time is exactly 00:00:00 or 12:00:00 is a little beyond what is expected.

  19. #19
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Incorrect Time Display

    it all comes down to culture.... the American culture uses AM/PM. So if you pick USA when you installed windows when it asks for your region, you get AM/PM time.

    If you live in some other country where they don't use AM/PM, then you would have picked that country, and the regional settings would be set accordingly, never showing you AM or PM for times because you don't know what they mean.

    And if you live in America, and you don't know what AM and PM are in terms of time, then the school system failed horribly.

    You can of course customize Windows to display the date/time however you want.
    Attached Images Attached Images  

  20. #20

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Incorrect Time Display

    If it isn't obvious I have thought about this before. My issue is an American issue, and one that I have resolved for myself through the use of military time.

    Sorry that I thought it might be fun to discuss this here, it isn't. I'm done.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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

    Re: Incorrect Time Display

    In 24-hour time format (without AM/PM), 12:00:00 represents midday so when converted to AM/PM format it will become 12:00:00 PM.

    In 24-hour time format (without AM/PM), 00:00:00 represents midnight so when converted to AM/PM format it will become 12:00:00 AM.

    Are your bosses paying you for doing this stuff?
    • 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

  22. #22

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Incorrect Time Display

    Yes I am paying myself.

    http://iconlogic.blogs.com/weblog/20...g-works-1.html

    I feel better knowing that there are a few billion people with the same issue ;-)

    http://forum.kasperskyclub.com/blog/...?showentry=272

    "And if you live in America, and you don't know what AM and PM are in terms of time, then the school system failed horribly." What does that mean?

    Are you speaking generally or in the particular case of 12AM / 12PM? If in general I wasn't failed, I know the difference between 1AM / 1PM. If, as I am guessing, you mean 12AM / 12PM maybe it isn't my school that failed. Could it be that the schools I attended knew that 12AM / 12PM were incorrect?

    For the record, it was my 9th grade Geometry teacher that started this. It was during a time when accepted did not mean right(Civil Rights). Maybe you read about it in History class.


    FYI - I submitted this to MSDN as a Suggestion. My instinct tells me it will be ignored by Microsoft.
    Last edited by dbasnett; Mar 6th, 2008 at 10:41 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  23. #23
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Incorrect Time Display

    Quote Originally Posted by dbasnett
    If I say lets meet at 12PM March 5th, when do I want to meet? At the boundary between march 5 - 6 or 4 - 5?
    Neither.

  24. #24
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Incorrect Time Display

    Quote Originally Posted by dbasnett
    If I say lets meet at 12PM March 5th, when do I want to meet? At the boundary between march 5 - 6 or 4 - 5?
    Noon on the 5th. What's the 4th or 6th got to do with it? Leave them out of it. They didn't do anything to you.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  25. #25

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Incorrect Time Display

    So far it(see post #23) has been ignored by Microsoft. Now there is a shock.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  26. #26
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: Incorrect Time Display

    To display it as military time, you need to use capital H's in the format:

    Code:
    Dim TestTime As DateTime
    
    TestTime = Convert.ToDateTime("12:00:00")
    
    Dim TestString As String = String.Format("{0:HH:mm}", TestTime)
    
    Debug.WriteLine(TestString & " <<--Error")
    That will get you 12:00 without am or pm

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