cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
uProf
Level III

Filter by 6 week duration, start of the week

Hi -

 

I am interested in filtering data based on time stamp in data between now and 6 weeks, starting from first day of the week (Sunday). This requires additional logic when new year begins.

 

I looked for date time functions and noticed date increment function that would provide 6 weeks in to the future. How can I get start date that is 6 weeks into the past?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Filter by 6 week duration, start of the week

Here is a little script that should give you a pointer towards solving your 6 week issue.

txnelson_0-1630889371195.png

Names Default To Here( 1 );
// put in any date using the format of mm/dd/yyyy
inDate = "07/21/2021";
jmpDate = Informat( inDate, "mm/dd/yyyy" );
// Calculate the date 6 weeks before, and adjust to the
// Sunday prior to the absolute 6 week date
sixWeeksBefore = jmpDate - In Weeks( 6 ) - In Days( Day Of Week( jmpDate ) - 1 );
// Calculate the date 6 weeks after, and adjust to the
// Sunday following
sixWeeksAfter = jmpDate + In Weeks( 6 ) + In Days( 8 - Day Of Week( jmpDate ) );

Dialog(
	"Input date is: " || Long Date( jmpDate ),
	"6 weeks before is: " || Long Date( sixWeeksBefore ),
	"6 weeks after is: " || Long Date( sixWeeksAfter )
);

Look in the Scripting Index for help with the different functions.

 

Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: Filter by 6 week duration, start of the week

Here is a little script that should give you a pointer towards solving your 6 week issue.

txnelson_0-1630889371195.png

Names Default To Here( 1 );
// put in any date using the format of mm/dd/yyyy
inDate = "07/21/2021";
jmpDate = Informat( inDate, "mm/dd/yyyy" );
// Calculate the date 6 weeks before, and adjust to the
// Sunday prior to the absolute 6 week date
sixWeeksBefore = jmpDate - In Weeks( 6 ) - In Days( Day Of Week( jmpDate ) - 1 );
// Calculate the date 6 weeks after, and adjust to the
// Sunday following
sixWeeksAfter = jmpDate + In Weeks( 6 ) + In Days( 8 - Day Of Week( jmpDate ) );

Dialog(
	"Input date is: " || Long Date( jmpDate ),
	"6 weeks before is: " || Long Date( sixWeeksBefore ),
	"6 weeks after is: " || Long Date( sixWeeksAfter )
);

Look in the Scripting Index for help with the different functions.

 

Jim
uProf
Level III

Re: Filter by 6 week duration, start of the week

Appreciate your help, Txnelson. Thanks a bunch!

jthi
Super User

Re: Filter by 6 week duration, start of the week

Date Increment is in my opinion best way to go with this. It might be a bit difficult to understand first but after that it is fairly easy. To go back in time you can use negative increment.

 

Names Default To Here( 1 );
// put in any date using the format of mm/dd/yyyy
inDate = "07/21/2021";
jmpDate = Informat(inDate, "Locale Date");
Show(Date Increment(jmpDate, "week", 6, "start"));
Show(Date Increment(jmpDate, "week", -6, "start"));

 

 

-Jarmo

Recommended Articles