Results 1 to 22 of 22

Thread: 24 HRS Format

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Posts
    164

    Question 24 HRS Format

    Can we set the format of Date time picker to 24 Hours instead of 12 AM/PM ??


    Thanks

  2. #2
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    VB Code:
    1. Private Sub Form_Load()
    2.     DTPicker1.Format = dtpCustom
    3.     DTPicker1.CustomFormat = Format(Now, "HH:MM:SS")
    4.     DTPicker1.Value = Now()
    5. End Sub
    McGenius

  3. #3

  4. #4
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Do you see any major diffence between "HH:mm:ss" and Format(Now, "HH:MM:SS") ???
    Last edited by McGenius; Apr 9th, 2003 at 10:04 AM.
    McGenius

  5. #5

  6. #6
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Originally posted by Wokawidget
    ... The code I posted above seems more logical ...
    In what sense?
    McGenius

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Because your code essentially does:
    VB Code:
    1. DTPicker1.CustomFormat = "16:08:34"
    Which means nothing...it works, but I don't know why...

    It's easier to read and debug, IN MY OPINION, if you use:
    VB Code:
    1. DTPicker1.CustomFormat = "HH:mm:ss"
    However, as you have stated before, I post stupid and pointless things...
    Maybe it's just me...

    Woka

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    MCGenius, not to gang up on your or anything.

    I just tried your code and although it does show the correct time, my datepicker control is basically disabled. I cannot change the date using the scrollbars, manually etc.. nothing.

    The CustomFormat property is used to specify the date format not an actual date, as in your code.

  9. #9
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    And McGenius's code doesn't work properly.
    It displays the time correct, but the control can't be editted anymore. It seems to be read-only.
    It seems useless to use the calender if you only display time, so I set the updown property to true. Editing the time with McGenius's code doesn't seem to work, while the following code works fine.
    VB Code:
    1. Private Sub Form_Load()
    2.     DTPicker1.Format = dtpCustom
    3.     DTPicker1.CustomFormat = "HH:mm:ss"
    4.     DTPicker1.UpDown = True
    5.     DTPicker1.Value = Now()
    6. End Sub
    Frans

  10. #10
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Originally posted by brucevde
    ... The CustomFormat property is used to specify the date format not an actual date, as in your code.
    And that's what it's for ...
    McGenius

  11. #11
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Originally posted by Frans C
    ...It displays the time correct, but the control can't be editted anymore. It seems to be read-only...
    That's entirely different issue.
    Although, when I need to buy say pair of shoes - I 'll buy it from a shoe store (not from a department store that knows very little about the shoes). The same if I need to format some string I would always use Format function and nothing less than that.
    McGenius

  12. #12

  13. #13
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Originally posted by McGenius
    That's entirely different issue.
    Although, when I need to buy say pair of shoes - I 'll buy it from a shoe store (not from a department store that knows very little about the shoes). The same if I need to format some string I would always use Format function and nothing less than that.
    What?! What have shoes got to do with the price of fish?

    The Format, or Format$, commands do format data into the desired format, BUT you can't pass this into CustomFormat property as this requires "HH:mm:ss" or something along those lines...

    Woka

  14. #14
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Code inside the DatePicker control will do something like:

    VB Code:
    1. Option Explicit
    2.  
    3. Private mstrFormat  As String
    4. Private mdteValue  As Date
    5.  
    6. Public Property Let CustomFormat(ByVal pstrValue As string)
    7.    mstrFormat = pstrValue
    8.    RefreshDisplay
    9. End Property
    10.  
    11. Public Property Get CustomFormat() As String
    12.    CustomFormat = mstrFormat
    13. End Property
    14.  
    15. Public Property Let Value(ByVal pdteValue As date)
    16.    mdteValue = pdteValue
    17.    RefreshDisplay
    18. End property
    19.  
    20. Public Property Get Value() As Date
    21.    Value = mdteValue
    22. End Property
    23.  
    24. Private Sub RefreshDisplay()
    25.    txtDisplay.Text = Format$(mdteValue, mstrFormat)
    26. End Sub
    Since you use:
    VB Code:
    1. DTPicker1.CustomFormat = Format(Now, "HH:MM:SS")
    Then mstrFormat will equal something like 16:32:28
    So when it comes to display the data in the RefreshDisplay sub you will infact actually be doing:
    VB Code:
    1. Private Sub RefreshDisplay()
    2.    txtDisplay.Text = Format$(mdteValue, "16:32:28")
    3. End Sub
    Which will basically just assign some random text to the text box. This is why it can't be edited as the datepicker control doesn't recognise any part of this as a date or time...

    Woka

  15. #15
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    A test to check it works is run your code, with the following added...then wait 10-20 seconds, and click the command button and see if the value in the DP gets updated
    VB Code:
    1. Private Sub Command1_Click()
    2.    DatePicker1.Value = Now
    3. End Sub
    Nothing happens, the display WILL NEVER change since your custom format is random text and is not recognised...

    Woka

  16. #16
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    You are real moron, Woka ...
    McGenius

  17. #17
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    As I noticed before, a discussion with McGenius isn't really worth the effort.
    Frans

  18. #18

  19. #19
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Originally posted by Frans C
    As I noticed before, a discussion with McGenius isn't really worth the effort.
    I will take any opinion than does make sense, but if you don't have one - don't bother ...
    McGenius

  20. #20
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Jesus christ would you stop trying to annoy people!!!
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  21. #21
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    Just started ... MG ;-)
    McGenius

  22. #22
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Originally posted by McGenius
    I will take any opinion than does make sense, but if you don't have one - don't bother ...
    That doesn't make sense...!
    Unlike your VB code you posted...oh, no, wait...That didn't make sense either

    Woka

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