2012-08-27 5 views
2

내 일이라고 말할 수 있습니다 :Vb.net 현재 날짜 - 날짜

Dim theDate As DateTime = DateTime.ParseExact("2013-04-10 21:34 PM", "yyyy-MM-dd HH:mm tt", CultureInfo.InvariantCulture) 
Dim currentTime As System.DateTime = System.DateTime.Now 
dim Result as new datetime 
Result = currentTime.Date - theDate 

업데이트 :

내가 시도 :

Dim currentTime As System.DateTime = System.DateTime.Now 
Dim date1 As New System.DateTime(2013, 4, 10, 21, 34, 10) 
Dim date2 As New System.DateTime(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, currentTime.Minute, currentTime.Second) 
Dim diff1 As System.TimeSpan 
diff1 = date2.Subtract(date1) 
MsgBox(diff1.ToString) 
+1

당신은 형제, diff1.XYZ는 (연도, 달, 일 등 날짜 범위) 'XYZ'가 아닌 감사'TimeSpan' –

답변

4

TimeSpan 당신이 날짜를 뺄 수 있습니다. 여기

Dim date1 As New System.DateTime(1996, 6, 3, 22, 15, 0) 
Dim date2 As New System.DateTime(1996, 12, 6, 13, 2, 0) 

Dim diff1 As System.TimeSpan 
' diff1 gets 185 days, 14 hours, and 47 minutes. 
diff1 = date2.Subtract(date1) 

MsgBox(diff1.Days) 
MsgBox(diff1.Hours) 
MsgBox(diff1.Minutes) 

DateTime.Subtract Method (TimeSpan)

모든 members of the TimeSpan class

+0

필요가 있습니다 'System.TimeSpan'의 회원 – ffs

+0

내 업데이트를 보시고 틀린 말을하십시오 – ffs

+0

안녕하세요, 제 편집을 참조하십시오. –