AnsweredAssumed Answered

script to find next month's records

Question asked by JohnWolcott on Dec 11, 2010
Latest reply on Dec 14, 2010 by raybaudi


script to find next month's records


I am trying to write a script that will find all records that have a date which occurs next month.  I have created variables

($_start_month) which equals Month(Get(CurrentDate)) + 1

($_end_month) which equals Month(Get(CurrentDate)) + 2

($_start_year) which equals If (Month(Get(CurrentDate))=12; Year(Get(CurrentDate))+1; Year(Get(CurrentDate)))

The following script steps work:

SetField [Dates:zz_Heading__gt; MonthName($_start_month) & " " & $_start_year]

Enter Find Mode[]

SetField [Dates::Date; Date($_start_month ; 1 ; Year(Get(CurrentDate))) & "...<" & Date($_end_month ; 1 ; Year(Get(CurrentDate)))

Perform Find []

It took about an hour to figure out I needed the space before the field separators, i.e. the ";".  I'm still not clear why the year is automatically updated when I add the vaule "1" to the Month when I use the variables in the find mode but is not updated for the heading field.  I assume it is because one is a date field type and the other is a text field type. 

Since it is December, everything works, but come next November, will the year be correct, which should be the current year since the next month will be December, or will the year be the following year because the the variable ($_end_month) adds the value 2 to the month, which would take it into the follwoing year or is the date for the start month stored as a complete date (not just the month) and the date for the end month stored as a separate complete date, which is what I hope?

Is there a better way to approach this search?