Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am trying to match between DateTimePicker and Date but I am unable to.
Please help me soon.

It does not show match
VB
date1 = rightNow.ToString
date2 = DateTimePicker1.ToString
MsgBox("RightNow: " & date1)
MsgBox("Pickedate1: " & date2)        
If date1 = date2 Then
    MessageBox.Show("Match the date")
End If
Posted
Updated 17-May-10 0:55am
v2

You are trying to compare two strings. They might not be the same. If your goal is to match two dates then it would be good if you compare dates like:
VB
date1 = rightNow
date2 = DateTimePicker1.Date
If date1 = date2 Then
 MessageBox.Show("Match")
End If


Incase you are having any problem in getting date, convert the strings into date!
 
Share this answer
 
Comments
Emon Mahmud 17-May-10 7:30am    
Dear,
DateTimePicker1.Date can not assign into the date2.
Please help me.
Thanks
Take a sub part of the string.
        Dim str As String
        Dim et As String
        str = Left(Date.Now, 10)

        et = Left(str, 10)

        If str = et Then
            MsgBox("Match the date")
        End If

//   Cheers
 
Share this answer
 
v2
Comments
Emon Mahmud 17-May-10 7:29am    
Thanks for your advice but i have faced some problem with 'SubString'
Pls help me again
For starters you want the Value from the DateTimePicker then if you are only concerned with the date you can strip out the time by;
VB
Dim date1 As Date
Dim date2 As Date
date1 = DateTime.Now.Date
date2 = DateTimePicker1.Value.Date
MsgBox("RightNow: " & date1)
MsgBox("Pickedate1: " & date2)
If date1 = date2 Then
    MessageBox.Show("Match the date")
End If


If you want to convert the DateTime values to strings you can use;
VB
Dim date1 As String
Dim date2 As String
date1 = DateTime.Now.ToString("dd MMM yyyy")
date2 = DateTimePicker1.Value.ToString("dd MMM yyyy")
MsgBox("RightNow: " & date1)
MsgBox("Pickedate1: " & date2)
If date1 = date2 Then
    MessageBox.Show("Match the date")
End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900