我在VB6中有一個簡單的程序。我有兩個文本框和一個列表框。我已經把日期範圍放在文本框中,結果出現在列表框中。例如一個文本框02/05/2012和另一個文本框02/10/2012。結果進來列表框中獲取在給定兩個日期之間的範圍
02/05/2012 02/06/2012 02/07/2012 02/08/2012 2012年2月9日 02/10/2012
任何一個引導我
我在VB6中有一個簡單的程序。我有兩個文本框和一個列表框。我已經把日期範圍放在文本框中,結果出現在列表框中。例如一個文本框02/05/2012和另一個文本框02/10/2012。結果進來列表框中獲取在給定兩個日期之間的範圍
02/05/2012 02/06/2012 02/07/2012 02/08/2012 2012年2月9日 02/10/2012
任何一個引導我
請參閱MSDN的這個頁面,它解釋了DateDiff函數的工作原理:http://msdn.microsoft.com/en-us/library/b5xbyt6f(v=vs.90).aspx。現在只需要從列表框中檢索數據。
如果您使用的是JavaScript,然後再看到這樣一個
function (startDate, endDate, addFn, interval) {
addFn = addFn || Date.prototype.addDays;
interval = interval || 1;
var retVal = [];
var current = new Date(startDate);
while (current <= endDate) {
retVal.push(new Date(current));
current = addFn.call(current, interval);
}
return retVal;
}
Dim dtStart As Date, dtEnd As Date
If Not IsDate(Text1) Then
MsgBox "Text1 does not contain a valid date"
' Exit Sub/Function
End If
If Not IsDate(Text2) Then
MsgBox "Text2 does not contain a valid date"
' Exit Sub/Function
End If
dtStart = CDate(Text1)
dtEnd = CDate(Text2)
' Clear the listbox
List1.Clear
Dim d As Date
For d = dtStart To dtEnd
List1.AddItem d
Next