Question Datetimepicker Time value comparison

dyomzkie

New member
Joined
Aug 7, 2011
Messages
3
Programming Experience
Beginner
Hi,

im trying to compare time value of to two datetimepickers, i tried to use dt_Start.Value.TimeOfDay > dt_End.Value.TimeOfDay but it doesn't work.
btw, i trying to make a scheduler. here are some of my codes:
 Dim strUpdate As String


        If dt_Start.Value.Date > dt_End.Value.Date Then
            MsgBox("End date is earlier than Start Date. Please check.", vbExclamation, "Error!")
        ElseIf dt_Start.Value.Date < Today.Date Then
            MsgBox("Selected date is later than the current date. Please check.", vbExclamation, "Error!")
        ElseIf dt_Start.Value.Date <= dt_End.Value.Date Then


            [B]If dt_Start.Value.TimeOfDay > dt_End.Value.TimeOfDay Then[/B]
[B]                MsgBox("End time is earlier than the Start time. Please check.", vbExclamation, "Error!")[/B]
            ElseIf dt_Start.Value.TimeOfDay <= dt_End.Value.TimeOfDay Then


                If MsgBox("Do you want to save record?", MsgBoxStyle.YesNo + vbQuestion, "Save Record") = vbYes Then


                    If rtxt_Desc.Text = "" Or cmb_Name.Text = "" Then
                        MsgBox("Please fill-up ALL the necessary information.", MsgBoxStyle.Critical, vbOK)
                    Else
                        dt_Start.CustomFormat = "yyyy-MM-dd hh:mm:ss"
                        dt_End.CustomFormat = "yyyy-MM-dd hh:mm:ss"




                        strUpdate = "INSERT INTO tbl_sched(strdte, enddte, nme, des, status, dtecreate) VALUES('" + dt_Start.Text + "', '" + dt_End.Text + "','" + cmb_Name.Text + "', '" + rtxt_Desc.Text + "', '" + cmb_Status.Text + "',Now())"
                        Con.noReturnQuery(strUpdate)
                        'MsgBox(strUpdate)
                        MsgBox("Record Save.")
                        Me.Close()
                    End If


                End If


            End If


        End If


    End Sub
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,295
Location
Sydney, Australia
Programming Experience
10+
You're going to have to define "doesn't work" because I can tell you that this:
Code:
If dt_Start.Value.TimeOfDay > dt_End.Value.TimeOfDay Then
is going to do exactly what you think it is. Maybe the problem is the line before it:
Code:
ElseIf dt_Start.Value.Date <= dt_End.Value.Date Then
If the start date is less than the end date then why would it matter whether the start time is after the end time?
 

dyomzkie

New member
Joined
Aug 7, 2011
Messages
3
Programming Experience
Beginner
thanks for the reply. i think i've already resolved the problem. i have tried to rewrite everything, and it already worked.:biggrin:
 
Top Bottom