Record selection based on Next Sunday through end of 2 months out - crystal-reports

I want to pull all records from the {#Calc Promise Date} field that have a date range of next Sunday through the end of next month. I have the end of next month part, and tried the next Sunday part using some similar examples on this site, but I am still off target on the next Sunday part.
Original try that would have a start of 5 days after today:
{#Calc Promise Date}>=DateSerial(Year(currentdate),Month(currentdate),Day(currentdate)+5)
and {#Calc Promise Date}<DateSerial(Year(currentdate),Month(currentdate)+2,1)
This was modified from help given to another user, but does not cover how to adjust the start date of the range to next Sunday.
I tried the following and have errors as I do not understand the correct layout, or if this will help in getting my desired start date.
{#Calc Promise Date} >= if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 1
then DateSerial(Year(currentdate),Month(currentdate),1+7)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 2
then DateSerial(Year(currentdate),Month(currentdate),1+6)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 3
then DateSerial(Year(currentdate),Month(currentdate),1+5)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 4
then DateSerial(Year(currentdate),Month(currentdate),1+4)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 5
then DateSerial(Year(currentdate),Month(currentdate),1+3)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 6
then DateSerial(Year(currentdate),Month(currentdate),1+2)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 7
then DateSerial(Year(currentdate),Month(currentdate),1+1)
and {#Calc Promise Date}<DateSerial(Year(currentdate),Month(currentdate)+2,1)

You are almost done as per my knowledge writing this formula in Record Selection doesn't work instead create saperate formulas and write on liner in record selection.
Create a formula Start Date:
if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 1
then DateSerial(Year(currentdate),Month(currentdate),1+7)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 2
then DateSerial(Year(currentdate),Month(currentdate),1+6)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 3
then DateSerial(Year(currentdate),Month(currentdate),1+5)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 4
then DateSerial(Year(currentdate),Month(currentdate),1+4)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 5
then DateSerial(Year(currentdate),Month(currentdate),1+3)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 6
then DateSerial(Year(currentdate),Month(currentdate),1+2)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 7
then DateSerial(Year(currentdate),Month(currentdate),1+1)
and {#Calc Promise Date}<DateSerial(Year(currentdate),Month(currentdate)+2,1)
Create a Formula End Date:
DateSerial(Year(currentdate),Month(currentdate)+2,1)
Now your Record Selection:
{#Calc Promise Date}>={#Start Date}
and {#Calc Promise Date}<{#End Date}

Related

fb prophet regressor underestimated

I am working on monthly sales data. especially in the month of June, the sales are almost 3*X. how do I add a regressor? I tried to create a binary regressor but the value is still underestimated. how can I increase the impact of the regressor?
def main_season(ds):
date = pd.to_datetime(ds)
if date.month > 3 and date.month < 7:
return 1
else:
return 0
X_tr['main_season'] = X_tr['ds'].apply(main_season)
def peak_season(ds):
date = pd.to_datetime(ds)
if date.month == 6:
return 1
else:
return 0
X_tr['peak_season'] = X_tr['ds'].apply(peak_season)

Getting two outputs instead of one in Matlab

The question here was to find if the date provided is a valid one or not without using native Matlab date functions. I was hoping if someone can point out my mistake here. I'm also getting the "Output argument valid (and maybe others) not assigned during call to valid_date" error in Matlab learning tool when I submit it.
function valid = valid_date(year,month,day)
if nargin~=3
valid = false;
elseif ~isscalar(year)||year<1||year~=fix(year)
valid = false;
return
elseif ~isscalar(month)||month<1||month~=fix(month)
valid = false;
return
elseif ~isscalar(day)||day<1||day~=fix(day)
valid = false;
return
elseif month>12 || day > 31
valid = false;
end
if ((mod(year,4)==0 && mod(year,100)~=0) || mod(year,400)==0)
leapdata=1;
else
leapdata=0;
end
%the below if statements are used to define the months. Some months have
%31 days and others have 30 days, while February has only 28 days and 29 on
%leap years. this is checked in the below code.
% I feel the below code is where the error is.
if ismember (month, [1 3 5 7 8 10 12])
ismember (day, (1:31))
return
elseif ismember( month, [4 6 9 11])
ismember (day, (1:30))
return
end
if month == 2
if leapdata==1
ismember (day, (1:29))
return
elseif leapdata==0
ismember (day, (1:28))
return
else
valid = false;
end
end
When returning at the end of a Matlab function, the value of the variable valid is sent as an output. In the lines below the four comments, you need to assign the variable to true or false inside of the if statements. For example:
if ismember(month, [1 3 5 7 8 10 12])
valid = ismember(day, (1:31))
return
elseif ismember(month, [4 6 9 11])
valid = ismember(day, (1:30))
return
end
if month == 2
if leapdata == 1
valid = ismember(day, (1:29))
return
elseif leapdata == 0
valid = ismember(day, (1:28))
return
else
valid = false;
end
end

Find how many sundays in a month asp classic

I am trying to use asp classic to find how many working days (mon - sat) are in the month and how many are left.
any help or pointers greatly appreciated!
Here's how you can find the number of Sundays in a month without iteration. Somebody posted a JavaScript solution a few months back and I ported it to VBScript:
Function GetSundaysInMonth(intMonth, intYear)
dtmStart = DateSerial(intYear, intMonth, 1)
intDays = Day(DateAdd("m", 1, dtmStart) - 1)
GetSundaysInMonth = Int((intDays + (Weekday(dtmStart) + 5) Mod 7) / 7)
End Function
So, your total work days would just be the number of days in the month minus the number of Sundays.
Edit:
As #Lankymart pointed out in the comments, the above function gives you the number of Sundays in the month but it doesn't tell you how many are left.
Here's another version that does just that. Pass in any date and it will tell you how many Sundays are left in the month starting with that date. If you want to know how many Sundays are in a full month, just pass in the first day of the month (e.g., DateSerial(2014, 8, 1)).
Function GetSundaysRemainingInMonth(dtmStart)
intDays = Day(DateSerial(Year(dtmStart), Month(dtmStart) + 1, 1) - 1)
intDays = intDays - Day(dtmStart) + 1
GetSundaysRemainingInMonth = Int((intDays + (Weekday(dtmStart) + 5) Mod 7) / 7)
End Function
Edit 2:
#Cheran Shunmugavel was interested in some specifics about how this works. First, I just want to restate that I didn't develop this method originally. I just ported it to VBScript and tailored it to the OP's requirement (Sundays).
Imagine a February during a leap year. We have 29 days during the month. We know from the start that we have four full weeks, so each weekday will be represented at least four times. But that still leaves one addition day that's unaccounted for (29 Mod 7 = 1). How do we know if we get an extra Sunday from that one day? Well, in this case, it's pretty simple. Only if our start date is a Sunday can we count an extra Sunday for the month.
What if the month has 30 days? Then we have two extra days to account for. In that case, the start date can be a Saturday or a Sunday and we can count an extra Sunday for the month. And so it goes. So we can see that if we're X additional days within an upcoming Sunday, we can count an extra Sunday.
Let's put this in tabular form:
Addl Days Needed
Day To Count Sunday
---------- ----------------
Sunday 1
Saturday 2
Friday 3
Thursday 4
Wednesday 5
Tuesday 6
Monday 7
So what we need is a formula that we can apply to these situations so that they all result in the same value. We'll need to assign some value to each day and combine that value with the number of addition days needed for Sunday to count. Seems reasonable that if we assign an inverse value to the weekdays and add that to the number of additional days, we can get the same result.
Addl Days Needed Value Assigned
Day To Count Sunday To Weekday Sum
---------- ---------------- -------------- ---
Sunday 1 6 7
Saturday 2 5 7
Friday 3 4 7
Thursday 4 3 7
Wednesday 5 2 7
Tuesday 6 1 7
Monday 7 0 7
So, if weekday_value + addl_days = 7 then we count an extra Sunday. (We'll divide this by 7 later to give us 1 additional Sunday). But how do we assign the values we want to the weekdays? Well, VBScript's Weekday() function already does this but, unfortunately, it doesn't use the values we need by default (it uses 1 for Sunday through 7 for Saturday). We could change the way Weekday() works by using the second param, or we could just use a Mod(). This is where the + 5 Mod 7 comes in. If we take the Weekday() value and add 5, then mod that by 7, we get the values we need.
Day Weekday() +5 Mod 7
---------- --------- -- -----
Sunday 1 6 6
Saturday 7 12 5
Friday 6 11 4
Thursday 5 10 3
Wednesday 4 9 2
Tuesday 3 8 1
Monday 2 7 0
That's how the + 5 Mod 7 was determined. And, with that solved, the rest is easy(er)!
#Zam is on the right track you need to use WeekDay() function, here is a basic idea of how to script it;
<%
Dim month_start, month_end, currentdate, dayofmonth
Dim num_weekdays, num_past, num_future
Dim msg
'This can be configured how you like even use Date().
month_start = CDate("01/08/2014")
month_end = DateAdd("d", -1, DateAdd("m", 1, month_start))
msgbox(Day(month_end))
For dayofmonth = 1 To Day(month_end)
currentdate = CDate(DateAdd("d", dayofmonth, month_start))
'Only ignore Sundays
If WeekDay(currentdate) <> vbSunday Then
num_weekdays = num_weekdays + 1
If currentdate <= Date() Then
num_past = num_past + 1
Else
num_future = num_future + 1
End If
End If
Next
msg = ""
msg = msg & "Start: " & month_start & "<br />"
msg = msg & "End: " & month_end & "<br />"
msg = msg & "Number of Weekdays: " & num_weekdays & "<br />"
msg = msg & "Weekdays Past: " & num_past & "<br />"
msg = msg & "Weekdays Future: " & num_future & "<br />"
Response.Write msg
%>
How about using "The Weekday function returns a number between 1 and 7, that represents the day of the week." ?

Get today -2 (skipping weekend)

How can I get the Today -2 days (the last 2 working days from now)? but skipping the weekend?
Example #1: Today is February 25, I want February 21
Example #2: Today is February 26, I want February 24
PS: Date format is DD/MM/YYYY
I have this, but the result is going forward, should I use datediff or what?:
<%
Dim d
d = DateAdd("m", 1, Now)
d = "01/" & Month(d) & "/" & Year(d)
d = DateAdd("d", -1, d)
If Weekday(d) = 7 Then
d = DateAdd("d", -1, d)
ElseIf Weekday(d) = 1 Then
d = DateAdd("d", -2, d)
End If
Response.Write "Day: " & d
%>
To get your desired result you need to subtract 3 days on Saturdays, 4 days on Sundays and Mondays, and 2 days on all other days. This can be achieved with something like this:
today = Now
num = Weekday(today, vbWednesday)
d = today - (2 + num\5 + num\6)
response.write "Two working days back: " & d
The Weekday function returns a numeric value for each weekday. By basing the week on Wednesday you can calculate the additional number of days you need to subtract from the current date with integer divisions:
num\5 returns 1 for Saturday, Sunday and Monday, and 0 otherwise.
num\6 returns 1 for Sunday and Monday, and 0 otherwise.
Thus the term 2 + num\5 + num\6 becomes 3 for Saturdays, 4 for Sundays and Mondays, and 2 for all other days.
This might be overkill for what you need but here are two routines I use in my scripts to add or subtract workdays while considering weekends and holidays.
Function AddWorkingDays(dtStart, intDays)
' Start/Default case...
AddWorkingDays = CDate(dtStart)
' If positive days, step forward, otherwise step backward...
Dim intStep, intCount
If intDays > 0 Then intStep = 1 Else intStep = -1
Do While intCount <> intDays
AddWorkingDays = AddWorkingDays + intStep
If IsValidDate(AddWorkingDays) Then intCount = intCount + intStep
Loop
End Function
Function IsValidDate(d)
Dim intWeekday, intMonth, intDay
intWeekday = Weekday(d)
intMonth = Month(d)
intDay = Day(d)
' Weekend dates are not acceptable...
If intWeekday = vbSaturday Or intWeekday = vbSunday Then Exit Function
' Holidays are also not acceptable...
If intMonth = 01 Then If intDay = 01 Then Exit Function ' New Year's Day
If intMonth = 07 Then If intDay = 04 Then Exit Function ' Independence Day
If intMonth = 12 Then If intDay = 25 Then Exit Function ' Christmas Day
' Memorial Day is the last Monday in May...
If intWeekday = vbMonday Then If intMonth = 05 Then If intDay >= 25 Then Exit Function
' ... (Thanksgiving, others) ...
' All tests passed. Date is a valid workday...
IsValidDate = True
End Function

Comparing two Date values in ActionScript - possible to compare whole day values?

I need to be able to compare the number of whole days between two dates in ActionScript, is this possible?
I'd like to test if one date is 7 days or less after today, and if so is it one day or less (if it's before today this also counts).
The workaround I have in place is using the .time part of the date field:
// Get the diffence between the current date and the due date
var dateDiff:Date = new Date();
dateDiff.setTime (dueDate.time - currentDate.time);
if (dateDiff.time < ( 1 * 24 * 60 * 60 * 1000 ))
return "Date is within 1 day");
else if (dateDiff.time < ( 7 * 24 * 60 * 60 * 1000 ))
return "Date is within 7 days");
As I say - this is only a workaround, I'd like a permanent solution to allow me to check the number of whole days between 2 dates. Is this possible?
Thanks
var daysDifference:Number = Math.floor((dueDate.time-currentDate.time)/(1000*60*60*24));
if (daysDifference < 2)
return "Date is within 1 day";
else if (daysDifference < 8)
return "Date is within 7 days";