获取范围日期并搜索字符串 [英] Get a range date and search a string

查看:137
本文介绍了获取范围日期并搜索字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个日期输入字段,开始结束,我有一个字符串,我想搜索一系列日期,范围在开始结束

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.

例如:

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

MyText 中搜索,如果其中一个日期在其中。如果是,我将 Response.Write 某事。

And search in the MyText, if one of the dates are inside it. If yes, I will Response.Write something.

起初我不知道如何获取数组(?)基于开始结束输入字段的日期。而且,我可以使用 InStr 搜索字符串,但是如何搜索数组(?)

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
%>


推荐答案

strStartDate将是您的开始日期

strStartDate will be your start date

strEndDate将是您的结束日期

strEndDate will be your end date

我们首先做的是设置我们是否找到您的字符串的默认值。接下来,我们会以几天为单位找出您的开始和结束日期之间的差异,然后在开始和结束日期之间的每一天循环。我们使用DateAdd函数来确定从一开始就进入循环的距离,然后我们使用DateAdd函数搜索MyText字符串。如果我们找到它,我们将boolDateFound变量设置为True并退出循环。

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.

<%
boolDateFound = False
For intDateDiff = 0 to DateDiff("d",strStartDate,strEndDate)

  arrDateParts = Split(DateAdd("d",intDateDiff,strStartDate),"/")
  If arrDateParts(1) <= 9 Then
    arrDateParts(1) = "0" & arrDateParts(1)
  End If
  strCheckDate = arrDateParts(0) & "/" & arrDateParts(1) & "/" & arrDateParts(2)

  Response.Write "Date: " & strCheckDate

  If InStr(MyText, strCheckDate) > 0 Then
    boolDateFound = True
    Exit For
  End If
Next

If boolDateFound Then%>
Found!
<%Else%>
Not Found
<%End If%>

这篇关于获取范围日期并搜索字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆