DateTimePicker和日期 [英] DateTimePicker and Date

查看:105
本文介绍了DateTimePicker和日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我正在尝试在DateTimePicker和Date之间进行匹配,但无法匹配.
请尽快帮助我.

它不显示匹配

Hello,
I am trying to match between DateTimePicker and Date but I am unable to.
Please help me soon.

It does not show match

date1 = rightNow.ToString
date2 = DateTimePicker1.ToString
MsgBox("RightNow: " & date1)
MsgBox("Pickedate1: " & date2)        
If date1 = date2 Then
    MessageBox.Show("Match the date")
End If

推荐答案

您正在尝试比较两个字符串.他们可能不一样.如果您的目标是匹配两个日期,那么比较以下日期将是很好的选择:
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:
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!


获取字符串的子部分.
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


对于初学者来说,您需要DateTimePicker中的Value,那么如果您只关心日期,则可以删除时间;
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;
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



如果要将DateTime值转换为字符串,可以使用;



If you want to convert the DateTime values to strings you can use;

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


这篇关于DateTimePicker和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆