Hi,
I have a DateTimePicker,whose
dateTimePicker1.Format = Time
dateTimePicker1.ShowUpDown = True
But now i want only the hour part from the Date Time Picker as i have to compare the hours with some logic in my Database.

Please Guide how cn i do this?

Recommended Answers

All 6 Replies

Try dateTimePicker1.value.hour

Try this,
dateTimePicker1.Format = Custom
dateTimePicker1.ShowUpDown = True
dateTimePicker1.Customformat = h

commented: :) +12

Try this,
dateTimePicker1.Format = Custom
dateTimePicker1.ShowUpDown = True
dateTimePicker1.Customformat = h

With DateTimePicker1
            .Format = DateTimePickerFormat.Custom
            .ShowUpDown = True
            '// .CustomFormat = "h" '// 12Hour.day
            .CustomFormat = "H" '// 24Hour.day
            MsgBox(.Value.Hour)
        End With

Try dateTimePicker1.value.hour

Hi,
acutally i want to save only the Hour part in the Database.I have set the format,custom format.
I have also tried using .hour but when i save i dont get 12 in the Hour value.
I want to save Data in Date column,right now according to my structure im saving data in this manner as shown below:
1/1/1900 10:53:00 AM
but i want to save it in this manner=>1/1/1900 10:00:00 AM
Even if the user selects the time in the Date Time Picker as 10:30:25 AM it should still save as 10:00:00 Am.
Properties of my DateTimePicker are:dtp.CustomFormat=hh
dtp.format=Time
dtp.ShowUpDown=True
Please guide how cn i do this

Hello

U can set the CustomFormat property of the picker to hh:00:00 tt
So that it can take only the hour part and not the minutes and seconds

hi !
set time format custom , hh , and then save like this , datetimepicker.text :)
Regards
M.Waqas Aslam

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.