This topic is locked
[SOLVED]

I want to show last week, this week, next week, date as filter. just like other wizards

8/13/2021 9:20:37 PM
PHPRunner General questions
M
muammer author

Hello
When intervallist is selected in the date filter field;
I want to show last week, this week, next week, date as filter. just like other wizards; I want it to come this month, next month.
What kind of code should I write so that I can show the weeks? Thank you very much to those who will explain step by step or give suggestions.

img alt

HJB 8/14/2021

Get week number (in the year) from a date PHP

I'm listing a sample code ex URL above to simply show what has to be observed here, say, things like LEAP YEAR and ISO definitions when a
week is really a week plus ISO definitions when a week starts are all about (in some countries a week starts on MONDAY, in others on SUNDAY).

I did NOT test the sample code below at all, but think, it is making clear that INTERVAL based filtering on a LAST WEEK, NEXT WEEK issue
first needs a new field to be installed as to enable the filter functionality to own a fixed starting point to work, hence all infos provided are for
inspiration purposes only. By the way, I'm personally interested in this as in the SHIPPING INDUSTRY, the week number of the year is playing
a signifcant role in regard to published schedules.

/**
* calcweek("2018-12-31") => 1901
* This function calculates the production weeknumber according to the start on
* monday and with at least 4 days in the new year. Given that the $date has
* the following format Y-m-d then the outcome is an integer.
*
* @author M.S.B. Bachus
*
* @param date-notation PHP "Y-m-d" showing the data as yyyy-mm-dd
* @return integer
**/
function calcweek($date) {
// 1. Convert input to $year, $month, $day
$dateset = strtotime($date);
$year = date("Y", $dateset);
$month = date("m", $dateset);
$day = date("d", $dateset);

$referenceday = getdate(mktime(0,0,0, $month, $day, $year));
$jan1day = getdate(mktime(0,0,0,1,1,$referenceday[year]));

// 2. check if $year is a leapyear
if ( ($year%4==0 && $year%100!=0) || $year%400==0) {
$leapyear = true;
} else {
$leapyear = false;
}

// 3. check if $year-1 is a leapyear
if ( (($year-1)%4==0 && ($year-1)%100!=0) || ($year-1)%400==0 ) {
$leapyearprev = true;
} else {
$leapyearprev = false;
}

// 4. find the dayofyearnumber for y m d
$mnth = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
$dayofyearnumber = $day + $mnth[$month-1];
if ( $leapyear && $month > 2 ) { $dayofyearnumber++; }

// 5. find the jan1weekday for y (monday=1, sunday=7)
$yy = ($year-1)%100;
$c = ($year-1) - $yy;
$g = $yy + intval($yy/4);
$jan1weekday = 1+((((intval($c/100)%4)*5)+$g)%7);

// 6. find the weekday for y m d
$h = $dayofyearnumber + ($jan1weekday-1);
$weekday = 1+(($h-1)%7);

// 7. find if y m d falls in yearnumber y-1, weeknumber 52 or 53
$foundweeknum = false;
if ( $dayofyearnumber <= (8-$jan1weekday) && $jan1weekday > 4 ) {
$yearnumber = $year - 1;
if ( $jan1weekday = 5 || ( $jan1weekday = 6 && $leapyearprev )) {
$weeknumber = 53;
} else {
$weeknumber = 52;
}
$foundweeknum = true;
} else {
$yearnumber = $year;
}

// 8. find if y m d falls in yearnumber y+1, weeknumber 1
if ( $yearnumber == $year && !$foundweeknum) {
if ( $leapyear ) {
$i = 366;
} else {
$i = 365;
}
if ( ($i - $dayofyearnumber) < (4 - $weekday) ) {
$yearnumber = $year + 1;
$weeknumber = 1;
$foundweeknum = true;
}
}

// 9. find if y m d falls in yearnumber y, weeknumber 1 through 53
if ( $yearnumber == $year && !$foundweeknum ) {
$j = $dayofyearnumber + (7 - $weekday) + ($jan1weekday - 1);
$weeknumber = intval( $j/7 );
if ( $jan1weekday > 4 ) { $weeknumber--; }
}

// 10. output iso week number (YYWW)
return ($yearnumber-2000)*100+$weeknumber;
}
M
muammer author 8/14/2021

Thank you very much for your efforts, suggestion and sample code. However, I want to do it in phprunner as I show in the picture and other month, year, today, tomorrow through the wizard.

Something like this will work for me.
1- 7 days after today's date
2- 7 days before today's date

What code should I write in the fields numbered 1 more than and 2 Less than (where I put a question mark) in the picture?

HJB 8/14/2021

Last week

$value = date("Y-m-d", strtotime('-7 days'));

Next week

$value = date("Y-m-d", strtotime('+7 days'));

In both cases use "More than ..." field for code entries
and leave "Less than ..." totally blank.

M
muammer author 8/14/2021

As a solution, I applied your code exactly. worked successfully. you are great, thank you very much. It's great to have friends like you here.