I have 2 date input fields, Start and End, and I have a String whom I would like to search for a range of dates, the range between Start and End.
For example:
Start: 20/02/2014
End: 25/02/2014
MyText: "In 21/02/2014 something happened"
What I am trying to do is get the dates between Start and End, in this case:
20/02/2014
21/02/2014
22/02/2014
23/02/2014
24/02/2014
25/02/2014
And search in the MyText, if one of the dates are inside it. If yes, I will Response.Write
something.
At first I dunno how to get the array(?) of dates based on the Start and End input fields. And, I can search a string using InStr, but how to search for the array(?)
I just have a single date search, like:
<%
IF InStr(MyText, Now()) >= 1 THEN
%>
Found!
<%
ELSE
%>
Not Found!
<%
END IF
%>
Ah, you like small code:
(please note that
sd
is always one day ahead of the found date, you need an additionalIf found then exit do
to circumvent that).EDIT: After discussion in the comments, I think this is the better approach: Extract the date from the text and see if it is larger or equal than the startdate and smaller or equal than the end date:
Use a RegExp to find dd/mm/yyyy dates in your Text, generate a Date (DateSerial) from the parts of each string, compare the found date against the range, store if appropriate.
In Code:
output:
strStartDate will be your start date
strEndDate will be your end date
First thing we do is set the default value for whether or not we found your string. Next we find the difference between your start and end date in days, we then loop through every day between the start and end date. We use the DateAdd function to determine how far into the loop we are from the start, then we search the MyText string for the date found with the DateAdd function. If we find it, we set the boolDateFound variable to True and exit the loop.