Date Range Verification - VB question
I have a vbp code. i need to verify if a date falls within a specific range:
example:
BDate EDate DescBDate DescEDate Falls within range
10/1/2008 7/31/2009 7/1/2000 3/31/2009 YES
10/1/2008 7/31/2009 4/1/2009 6/30/2010 YES
8/1/2009 10/1/2009 8/1/1994 1/31/2009 NO
7/1/2008 9/30/2008 4/1/2009 6/30/2010 NO
Can someone tell me how to write the logic for the above date range?
Thanks,
Jupi
Re: Date Range Verification - VB question
You've got 4 fields and 4 dates where is the range?
Re: Date Range Verification - VB question
I want to verify if DescBdate and DescEDate falls within BDate and EDate.
thanks
Re: Date Range Verification - VB question
Here's a little pseudo-code:
Set a Flag to False.
Check first set of dates, and mark Flag.
Check next set of dates, and mark Flag.
Check value of Flag
or use SQL, like this: (although it's VB6 code)
Code:
Option Explicit
Private Sub Form_Load()
Dim dteDate As Date
Dim adoRec As ADODB.Recordset
dteDate = CDate("7 March 2005 10:04:00AM")
Set adoRec = GetRecordset(dteDate)
With adoRec
Do While Not .EOF
'your code goes here
MsgBox .Fields(0)
.MoveNext
Loop
.Close
End With
Set adoRec = Nothing
End Sub
Private Function GetRecordset(ByVal pdteSearchDate As Date) As ADODB.Recordset
Dim strSQL As String
Dim adoRec As ADODB.Recordset
strSQL = "SELECT * "
strSQL = strSQL & "FROM AS_Createsched "
strSQL = strSQL & "WHERE AS_Createsched.CSIN_dates = #" & Format$(pdteSearchDate, "d mmm yyyy") & "# "
strSQL = strSQL & "AND HOUR(AS_Createsched.CSIN_times) = " & Format$(pdteSearchDate, "hh") & " "
strSQL = strSQL & "AND MINUTE(AS_Createsched.CSIN_times) = " & Format$(pdteSearchDate, "nn") & " "
Set adoRec = New ADODB.Recordset
adoRec.Open strSQL, GetConnString, adOpenForwardOnly, adLockReadOnly
Set GetRecordset = adoRec
Set adoRec = Nothing
End Function
Private Function GetConnString() As String
GetConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db4.mdb;Persist Security Info=False"
End Function
Re: Date Range Verification - VB question
I think you need the BETWEEN statement
Re: Date Range Verification - VB question
Quote:
Originally Posted by
jojupi01
I have a vbp code. i need to verify if a date falls within a specific range:
example:
BDate EDate DescBDate DescEDate Falls within range
10/1/2008 7/31/2009 7/1/2000 3/31/2009 YES
10/1/2008 7/31/2009 4/1/2009 6/30/2010 YES
8/1/2009 10/1/2009 8/1/1994 1/31/2009 NO
7/1/2008 9/30/2008 4/1/2009 6/30/2010 NO
Can someone tell me how to write the logic for the above date range?
Thanks,
Jupi
How the input is given?
from Database? User interface??
Re: Date Range Verification - VB question
To make comparison between dates you'd need the Date data type.
I assume your dates like 10/1/2008 come as strings, so you have to convert them to Date before being able to compare them.
Code:
Dim BD as Date, ED as Date, MD as Date
BD = CDate("10/1/2008")
ED = CDate("7/31/2009")
MD = CDate("7/1/2000")
If BD <= MD And MD <= ED Then Print "in range" Else Print "out"
CDate can surely be used with string variables, too.
Assumed BDate and EDate were string variables then BD = CDate(BDate) would do the conversion for BDate.
Re: Date Range Verification - VB question
String variables can be used in a sql statement just fine as they are as stated earlier a SQL between statement sounds like the key. Of course the OP has not been back for a while so ...