-
August 28th, 2011, 12:43 AM
#1
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
-
August 28th, 2011, 01:51 AM
#2
Re: Date Range Verification - VB question
You've got 4 fields and 4 dates where is the range?
Always use [code][/code] tags when posting code.
-
August 28th, 2011, 02:00 AM
#3
Re: Date Range Verification - VB question
I want to verify if DescBdate and DescEDate falls within BDate and EDate.
thanks
-
August 28th, 2011, 10:12 AM
#4
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
-
August 29th, 2011, 02:21 AM
#5
Re: Date Range Verification - VB question
I think you need the BETWEEN statement
-
September 9th, 2011, 07:02 AM
#6
Re: Date Range Verification - VB question
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??
Encourage the efforts of fellow members by rating
Lets not Spoon Feed and create pool of lazy programmers
- ComIT Solutions
-
September 13th, 2011, 01:03 PM
#7
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.
-
September 13th, 2011, 04:06 PM
#8
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 ...
Always use [code][/code] tags when posting code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|