4 Replies Latest reply on Aug 21, 2013 12:28 PM by LaRetta

# Searching Timestamp field for Current Month and Previous Month

I should know this - I'm pretty sure it has something to do with a date function in a calculation inside a script... Help??

Thanks!

Darryl

• ###### 1. Re: Searching Timestamp field for Current Month and Previous Month

Darryl P wrote:

I'm pretty sure it has something to do with a date function in a calculation inside a script …

Use Set Field [ ] with this calculation as result

Let (

[

now = Get ( CurrentDate ) ;

yearNow = Year ( now ) ;

thisMonth = Month ( now ) ;

startDate = Date ( thisMonth - 1 ; 1 ; yearNow ) ;

endDate = Date ( thisMonth + 1 ; 0 ; yearNow )

] ;

startDate & ".." & endDate

)

• ###### 2. Re: Searching Timestamp field for Current Month and Previous Month

As Usual you are correct, Erolist.

With apologies for further dumb questions -

What is the next step in the script after Set Field with that calculation?

and

If I wanted to find current month only, would I just leave out the "-1"??

Thank You!

Darryl

• ###### 3. Re: Searching Timestamp field for Current Month and Previous Month

Darryl P wrote:

As Usual you are correct, Erolist.

If that were only so …

What is the next step in the script after Set Field with that calculation?

You'd write something like

Go to Layout //

Enter Find Mode [ No Pause ] // you can switch those two steps, which can speed things up if your target layout is a busy one

Set Field [ … ] // (as described above)

Perform Find

Error trapping left our for sake of brevity.

If I wanted to find current month only, would I just leave out the "-1"??

You could; but searching only for dates within the current month (or any single month, for that matter) is in fact much easier:

Just write – without using Let [], since it's not that complicated – Month ( Get ( CurrentDate ) ) - 1  & "/" & Year ( Get ( CurrentDate ) ) (this is the entire formula).

PS: it's erolst – lower case, no i!

• ###### 4. Re: Searching Timestamp field for Current Month and Previous Month

I believe you can also use this in your Set Field[]:

```Let ( d = Get ( CurrentDate ) ;
Timestamp ( Date ( Month ( d ) - 1 ; 1 ; Year ( d ) ) ; 0 ) & ".." & Timestamp ( Date ( Month ( d ) + 1 ; 0 ; Year ( d ) ) ; 86399 ) )

```