Matt Leach Posted August 29, 2009 Posted August 29, 2009 (edited) Im having trouble with a script that involves calculating a month. I have a field called "Assigned" that contains a date. What i am trying to do is create a script of all records that were assigned 1 month ago, 2 months ago, 3 months ago. So far, i have been able to figure out how to get the current date and take the month to subtracy by one like so: Month (Get (CurrentDate)) - 1 Now if i were to set that calculation as a variable of lets say $1_Month, how would i tell the program that i want to see all records whose assigned dates meet the criteria of the current month - 1, which would be July? Thanks Edited August 29, 2009 by Guest
comment Posted August 29, 2009 Posted August 29, 2009 (edited) Try something like: Enter Find Mode [] Set Field [YourTable::Assigned ; Let ( t = Get (CurrentDate) ; Date ( Month (t) - 1 ; 1 ; Year (t) ) & ".." & Date ( Month (t) ; 0 ; Year (t) ) ) ] Perform Find [] Or, if you want to use a variable for how many months ago: Enter Find Mode [] Set Field [YourTable::Assigned ; Let ( t = Get (CurrentDate) ; Date ( Month (t) - $monthsAgo ; 1 ; Year (t) ) & ".." & Date ( Month (t) - $monthsAgo + 1 ; 0 ; Year (t) ) ) Perform Find [] Edited August 29, 2009 by Guest
Matt Leach Posted August 30, 2009 Author Posted August 30, 2009 I am able to get that to work correctly for 1 month back but anything over that does not appear to work correctly unless i am doing something wrong. I used your first example whoch worked for 1 month ago so i tried it for 2 months ago by changing the script to -2: Let ( t = Get (CurrentDate) ; Date ( Month (t) - 2 ; 1 ; Year (t) ) & ".." & Date ( Month (t) ; 0 ; Year (t) ) ) That should give me all records with an assigned date of 7/1/09 - 7/31/09, but i am also getting records from June showing up. Am i using the script incorrectly?
comment Posted August 30, 2009 Posted August 30, 2009 For 2 months ago, it needs to be: Let ( t = Get (CurrentDate) ; Date ( Month (t) - 2 ; 1 ; Year (t) ) & ".." & Date ( Month (t) - 1 ; 0 ; Year (t) ) ) BTW, it's still August around here, so two months ago would be June.
Matt Leach Posted August 30, 2009 Author Posted August 30, 2009 Math is a little rusty, thanks. I'll give it a try
Recommended Posts
This topic is 5838 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now