Can we set the format of Date time picker to 24 Hours instead of 12 AM/PM ??
Thanks
Printable View
Can we set the format of Date time picker to 24 Hours instead of 12 AM/PM ??
Thanks
VB Code:
Private Sub Form_Load() DTPicker1.Format = dtpCustom DTPicker1.CustomFormat = Format(Now, "HH:MM:SS") DTPicker1.Value = Now() End Sub
Don't know why that works, but shouldn't it be:
???VB Code:
DTPicker1.CustomFormat = "HH:mm:ss"
Woka
Do you see any major diffence between "HH:mm:ss" and Format(Now, "HH:MM:SS") ???
Why?
The code I posted above seems more logical, and works...
Woka
In what sense?Quote:
Originally posted by Wokawidget
... The code I posted above seems more logical ...
Because your code essentially does:
Which means nothing...it works, but I don't know why...VB Code:
DTPicker1.CustomFormat = "16:08:34"
It's easier to read and debug, IN MY OPINION, if you use:
However, as you have stated before, I post stupid and pointless things...:rolleyes:VB Code:
DTPicker1.CustomFormat = "HH:mm:ss"
Maybe it's just me...
Woka
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.
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:
Private Sub Form_Load() DTPicker1.Format = dtpCustom DTPicker1.CustomFormat = "HH:mm:ss" DTPicker1.UpDown = True DTPicker1.Value = Now() End Sub
And that's what it's for ...Quote:
Originally posted by brucevde
... The CustomFormat property is used to specify the date format not an actual date, as in your code.
That's entirely different issue.Quote:
Originally posted by Frans C
...It displays the time correct, but the control can't be editted anymore. It seems to be read-only...
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.
The court has over-ruled McGenius...
Woka wins :D
I thought the code did work, but my testing was limited and I didn't try the up and downy things :(
Woka
What?! What have shoes got to do with the price of fish? :confused:Quote:
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.
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
Code inside the DatePicker control will do something like:
Since you use:VB Code:
Option Explicit Private mstrFormat As String Private mdteValue As Date Public Property Let CustomFormat(ByVal pstrValue As string) mstrFormat = pstrValue RefreshDisplay End Property Public Property Get CustomFormat() As String CustomFormat = mstrFormat End Property Public Property Let Value(ByVal pdteValue As date) mdteValue = pdteValue RefreshDisplay End property Public Property Get Value() As Date Value = mdteValue End Property Private Sub RefreshDisplay() txtDisplay.Text = Format$(mdteValue, mstrFormat) End Sub
Then mstrFormat will equal something like 16:32:28VB Code:
DTPicker1.CustomFormat = Format(Now, "HH:MM:SS")
So when it comes to display the data in the RefreshDisplay sub you will infact actually be doing:
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...VB Code:
Private Sub RefreshDisplay() txtDisplay.Text = Format$(mdteValue, "16:32:28") End Sub
Woka
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 :D
Nothing happens, the display WILL NEVER change since your custom format is random text and is not recognised...VB Code:
Private Sub Command1_Click() DatePicker1.Value = Now End Sub
Woka
You are real moron, Woka ...
As I noticed before, a discussion with McGenius isn't really worth the effort.
I take it you don't fancy a pint sometime then...?Quote:
Originally posted by McGenius
You are real moron, Woka ...
Woka
I will take any opinion than does make sense, but if you don't have one - don't bother ...Quote:
Originally posted by Frans C
As I noticed before, a discussion with McGenius isn't really worth the effort.
Jesus christ would you stop trying to annoy people!!!
Just started ... MG ;-)
That doesn't make sense...! :confused:Quote:
Originally posted by McGenius
I will take any opinion than does make sense, but if you don't have one - don't bother ...
Unlike your VB code you posted...oh, no, wait...That didn't make sense either :D
Woka