Does anyone have any idea how to set the DateTimePicker's UpDown buttons to add/minus 30mins only instead of 1min?

Recommended Answers

All 4 Replies

Use methods of DateTime type.


Thank you for your reply adata, but I don't think that small code solves my problem.

^ On the right side of the DateTimePicker is a updown button called UpDown(labeled on the properties).

I want my program to add or subtract 30 minutes every click on the UpDown(if the minute is selected beforehand). The default is 1min for add/subtract.

Does any one knows how to capture the event when up or down is clicked on the time picker?.

I've tried searching it, so please stop with -1 already.

Here's how I did this, only difference is I was going by 15 minute increments rather than 30.

Private Sub DateTimePicker1_ValueChanged(sender As Object, e As System.EventArgs) Handles DateTimePicker1.ValueChanged
    Select Case DateTimePicker1.Value.Minute
        Case 1, 16, 31, 46
            DateTimePicker1.Value = DateTimePicker1.Value.AddMinutes(14)
        Case 14, 29, 44
            DateTimePicker1.Value = DateTimePicker1.Value.AddMinutes(-14)
        Case 59
            DateTimePicker1.Value = DateTimePicker1.Value.AddMinutes(-74)
    End Select
End Sub


You can try this:

 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        DateTimePicker1.Format = DateTimePickerFormat.Time

    End Sub

    Private Sub DateTimePicker1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles DateTimePicker1.KeyDown
        If e.KeyValue = 38 Then ' Arrowkey Up
            ' up
            DateTimePicker1.Value = DateTimePicker1.Value.AddMinutes(30)
            e.SuppressKeyPress = True
        ElseIf e.KeyValue = 40 Then ' ArrowKey Down
            DateTimePicker1.Value = DateTimePicker1.Value.AddMinutes(-30)
            e.SuppressKeyPress = True
        End If
    End Sub

Change Minutes with the Arrowkeys Up and Down.

Be a part of the DaniWeb community

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