Tip

Search a date range over the Web

Need to search a range of dates based on a user's selection of a beginning and end? 2 Steps: Write the search string, and convert the date characters to ASCII. Here's the code!


STEP 1: On a search form in a query field, calc the search string. (In this example, INVOICE_DATE is the DATE field on the doc that needs to be in the range. StartDate and EndDate are fields on the Search form. Be sure that the field searched is a DATE. This will not work if the field is text. Also, be sure the date format used on the search form matches the stored format of the document.)

@If(StartDate!=""; "[INVOICE_DATE]>"+@Text(@Adjust(StartDate;0;0;-1;0;0;0))+"+AND+[INVOICE_DATE]<"+@Text(@Adjust(EndDate;0;0;1;0;0;0)); "");

STEP 2: Convert non URL characters to ASCII (i.e. /," ")

asciiString:=@ReplaceSubstring(@LowerCase(string);
" ":""":"#":"$":"&":"+":"/":":":";": "<":"=":">":"?":"@": "[":"\";
"%20":"%22":"%23":"%24": "%26":"%2B":"%2F":"%3A":"%3B": "%3C":"%3D":"%3E":"%3F":"%40": "%5B":"%5C";

@If(asciiString != ""; asciiString; "")

Your $$Return would have something like this: (SearchString is the field calculating the query in Step 1.)

viewPath+"?SearchView"+"&Query="+SearchString

NOTE: You may not use the greater than or equal to operator in a web search. You must seperate these out. In the case above, I adjust the dates by 1 day to include the days chosen in the range.

This was first published in September 2001

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.