programing

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

oldcodes 2023. 7. 3. 23:10
반응형

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

두 VB.NET Date 개체의 날짜 부분(시간이 아님)만 비교하려고 합니다.그렇게 할 수 있는 방법이 있습니까?

각각의 날짜 부분을 다음을 통해 가져갑니다.Date속성 및 두 가지 비교:

date1.Date.CompareTo(date2.Date)

또는:

If date1.Date < date2.Date Then

시간 범위를 사용할 수도 있습니다.

Dim ts As TimeSpan
ts = dt1 - dt2

ts.이제 두 날짜의 차이가 전체 날짜로 표시됩니다.

날짜 시간을 비교합니다.날짜 속성.

다음을 사용하여 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)

데이트. 지금.날짜: #12/4/2018 오전 12:00:00 #

날짜. 지금: #12/4/2018 03:23:34 #

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

언급URL : https://stackoverflow.com/questions/618878/how-to-compare-just-the-date-part-and-not-the-time-of-two-dates

반응형