두 날짜의 시간이 아닌 날짜 부분 만 비교하는 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/618878

  •  03-07-2019
  •  | 
  •  

문제

두 개의 vb.net 날짜 객체의 날짜 부분 (시간이 아닌 시간이 아닌)을 비교하고 싶습니다. 그렇게 할 방법이 있습니까?

도움이 되었습니까?

해결책

각각을 통해 각각의 날짜 부분을 가져 가십시오 Date 속성과 두 가지를 비교하십시오.

date1.Date.CompareTo(date2.Date)

또는:

If date1.Date < date2.Date Then

다른 팁

DateTime.Date 속성을 비교하십시오.

TimesSpan을 사용할 수도 있습니다

Dim ts As TimeSpan
ts = dt1 - dt2

Ts.Days는 이제 하루 종일 두 날짜의 차이를 갖습니다.

TXT1 날짜를 DD/mm/yyyy 사용으로 변경하십시오. myDateTime.ToShortDateString() 두 날짜가 동일한 형식이 될 것입니다. 그 다음에 :

if (DateTime.Compare(date1, date2) > 0) 
// which means ("date1 > date2")
if (DateTime.Compare(date1, date2) == 0) 
//which means ("date1 == date2");
if (DateTime.Compare(date1, date2) < 0) 
//which means ("date1 < date2");
Dim backDateCount As Integer = DateDiff(DateInterval.Day, CDate(dtpCheckIn.SelectedDate.Value).Date, Date.Now.Date)

날짜 .now.date : #12/4/2018 12:00:00 AM#

날짜 .now : #12/4/2018 03:23:34 PM#

Dim date1, date2 As Date
date1 = Date.Parse(dtpStart.Text)
date2 = Date.Parse(dtpEnd.Text)
If (DateTime.Compare(date1, date2) > 0) Then ' which means ("date1 > date2") 
    MessageBox.Show("يجب تحديد  الفترة للتاريخ بشكل صحيح  ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading)
    Exit Sub
End If
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top