jQuery Datepicker - how to set: datepicker1 + 1 day becomes minDate datepicker2 with the option to switch off Saturday and Sunday - datepicker

I want to set the service selection for my clients like this:
possibility of disabling services on Saturdays and / or Sundays (checbox - Saturday formid-1 fielid-4_1, Sunday formid-1 fieldi-4_2; by default enabled)
minDate datapicker1 - 2 days after today (formid 1, fieldid 1)
minDate datepicker2 - 1 day after minDate datapaicker1 (formid 1, fieldid 2)
Unfortunately, I don't have the skills. I can tell dateMin, dateMax but more complicated functions don't work.
Will someone help me? :)
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 1 && fieldId == 1 ) {
optionsObj.minDate = +2;
optionsObj.maxDate = +33;
}
return optionsObj;
} );

Related

Recurring for month and week in Flutter

I am trying to create a feature where I can transfer money by scheduling, so for that, I need a recurring option for the month and weak, And the problem that I face is, that if a user chooses the 31st of a month every month doesn't have the 31st, so the transaction should happen in that particular month's end date.
for example: If I start recurring date is 31st May 2022
no of transactions: 3
Current Output: Dates of transactions => 1st July 2022, 31st July 2022, 31st August 2022,
Correct Output: 30th June 2022, 31st July 2022, 31st August 2022,
Maybe something like I proposed here:
With lastDayOfMonth you could potentially do something like
extension AddMonth on DateTime {
DateTime addMonths([int amount = 1]) {
final plusXMonths = DateTime(year, month + amount, day);
final xMonthsAhead = DateTime(year, month + amount);
if (xMonthsAhead.lastDayOfMonth.compareTo(plusXMonths).isNegative) {
return xMonthsAhead.lastDayOfMonth;
} else {
return plusXMonths;
}
}
}
This proposition is based on this code that I created a PR for:
extension DateTimeLastFirstDay on DateTime {
/// Returns the Monday of this week
DateTime get firstDayOfWeek =>
isUtc ? DateTime.utc(year, month, day + 1 - weekday) : DateTime(year, month, day + 1 - weekday);
/// Returns the Sunday of this week
DateTime get lastDayOfWeek =>
isUtc ? DateTime.utc(year, month, day + 7 - weekday) : DateTime(year, month, day + 7 - weekday);
/// Returns the first day of this month
DateTime get firstDayOfMonth => isUtc ? DateTime.utc(year, month, 1) : DateTime(year, month, 1);
/// Returns the last day of this month (considers leap years)
DateTime get lastDayOfMonth => isUtc ? DateTime.utc(year, month + 1, 0) : DateTime(year, month + 1, 0);
/// Returns the first day of this year
DateTime get firstDayOfYear => isUtc ? DateTime.utc(year, 1, 1) : DateTime(year, 1, 1);
/// Returns the last day of this year
DateTime get lastDayOfYear => isUtc ? DateTime.utc(year, 12, 31) : DateTime(year, 12, 31);
}
Using the time package you could create a similar code for weeks.

Find all instances of a date in a date range - SQL Server

I need to find the price for an item for each financial year end date in a date range. In this case the financial year is e.g. 31 March
The table I have for example:
ItemID
Value
DateFrom
DateTo
1
10
'2019/01/01'
'2021/02/28'
1
11
'2021/03/01'
'2021/05/01'
SQL Fiddle
The SQL would thus result in the above table to be:
ItemID
Value
DateFrom
DateTo
1
10
'2019/01/01'
'2019/03/30'
1
10
'2020/03/31'
'2021/02/28'
1
11
'2020/03/01'
'2021/03/30'
1
11
'2020/03/31'
'2021/05/01'
You can solve it, but a prerequisite is the creation of a table called financial_years and filling it with data. This would be the structure of the table:
financial_years(id, DateFrom, DateTo)
Now that you have this table, you can do something like this:
select ItemID, Value, financial_years.DateFrom, financial_years.DateTo
from items
join financial_years
on (items.DateFrom between financial_years.DateFrom and financial_years.DateTo) or
(items.DateTo between financial_years.DateFrom and financial_years.DateTo)
order by financial_years.DateFrom;
The accepted answer is not correct, as it does not split out different parts of the year which have different values.
You also do not need a Year table, although it can be beneficial. You can generate it on the fly using a VALUES table.
Note also a better way to check the intervals overlap, using AND not OR
WITH Years AS (
SELECT
YearStart = DATEFROMPARTS(v.yr, 3, 31),
YearEnd = DATEFROMPARTS(v.yr + 1, 3, 31)
FROM (VALUES
(2015),(2016),(2017),(2018),(2019),(2020),(2021),(2022),(2023),(2024),(2025),(2026),(2027),(2028),(2029),(2030),(2031),(2032),(2033),(2034),(2035),(2036),(2037),(2038),(2039)
) v(yr)
)
SELECT
i.ItemID,
i.Value,
DateFrom = CASE WHEN i.DateFrom > y.YearStart THEN i.DateFrom ELSE y.YearStart END,
DateTo = CASE WHEN i.DateTo > y.YearEnd THEN y.YearEnd ELSE i.DateTo END
FROM items i
JOIN Years y ON i.DateFrom <= y.YearEnd
AND i.DateTo >= y.YearStart;

How to query mongoDB for a given date range?

I am using mongoose to query data for my node.js application for a given month where I accept the input for a year and month from the user.
This is what I am doing
var lastDay = 31
if (month == 3 || month == 5 || month == 8 || month == 10) lastDay = 30
else if (month == 1) lastDay = 28
var cookies = await Cookies.find({
docDate: {
"$gte": new Date(parseInt(year), parseInt(month), 1),
"$lte": new Date(parseInt(year), parseInt(month), lastDay)}}).sort("docDate");
When I try to query the db for the month of february, I am getting results only uptil the 26 Feb and the result also includes data from january.
Please help me figure out what I am doing wrong.
I think the issue is with the date that is passed to the query.
new Date(2021,01,01); --> 2021-01-31T16:00:00.000Z
new Date(Date.UTC(2021,01,01)); --> 2021-02-01T00:00:00.000Z
If the date field in the database is in UTC then try using new Date(Date.UTC(year, month, day))
Use moment.js library:
docDate: {
"$gte": moment().startOf('month').toDate(),
"$lte": moment().endOf('month').toDate()
}
moment() is the current time. In order to input specific day, use moment(year + '-' + month, "YYYY-MM") for example.

Is there a formula for upcoming date using formula in Google sheet based on condition?

I have a google sheet where I need to get the next upcoming date based on the start date set in column A
Any pointers are greatly appreciated? I am unable exhibit the efforts as I am completely new to this sort of recurrence using Google sheets
https://docs.google.com/spreadsheets/d/1g_UNg4MjDy3gFufpjZtMRkbBz80K3scQdZOaiAnZi7I/edit#gid=0
This behavior (the next date from today including today) could be implemented manually by this formula:
={
"Next date from today";
ARRAYFORMULA(
IFS(
A2:A >= TODAY(),
A2:A,
B2:B = "Daily",
TODAY() + MOD(TODAY() - A2:A, C2:C),
B2:B = "Weekly",
TODAY() + MOD(TODAY() - A2:A, 7 * C2:C),
B2:B = "Monthly",
EDATE(A2:A, ROUNDUP((12 * (YEAR(TODAY()) - YEAR(A2:A)) + (MONTH(TODAY()) - MONTH(A2:A)) - IF(DAY(TODAY()) < DAY(A2:A), 1, 0)) / C2:C, 0) * C2:C),
True,
""
)
)
}
For additional options (like "every 2nd monday of the month" and others) additional options should be implemented in that IFS part.
If you are interested in a trivial case where the next date from the start date (column F:F on the screenshot) is needed, then the formula would be much simpler:
={
"Next date";
ARRAYFORMULA(
IFS(
B2:B = "Daily",
A2:A + C2:C,
B2:B = "Weekly",
A2:A + 7 * C2:C,
B2:B = "Monthly",
EDATE(A2:A, C2:C),
True,
""
)
)
}
Again, for additional options you'll need to add corresponding part to the IFS.
You could use IFS to check Frequency, and:
If Daily, add Count value to start date.
If Weekly, add Count value multiplied by 7.
If Monthly, since not all months have the same duration, retrieve the YEAR, MONTH and DAY indexes, add Count to the MONTH index, and set a new DATE, EDIT: or as suggested by kishkin, use EDATE.
It could be something like this:
=ARRAYFORMULA(IFNA(IFS(
B2:B = "Daily", A2:A + C2:C,
B2:B = "Weekly", A2:A + 7 * C2:C,
B2:B = "Monthly", EDATE(A2:A,C2:C)
)))

vbscript asp - Find every Thursday in a given month

I'm trying to find all Thursdays within a given Month using VBScript.
Can anyone help?
Here is one way;
base_date = cdate("21 aug 2011")
'get 1st thursday;
thurs = dateserial(year(base_date), month(base_date), 1)
if (weekday(thurs) <> 1) then thurs = 5 - weekday(thurs) + thurs
'loop subsequent;
do until month(thurs) <> month(base_date)
msgbox thurs
thurs = dateadd("d", 7, thurs)
loop
While the accepted answer does the job it's overly complicated for something that can be accomplished with WeekDay() function and a For loop.
Dim day
Dim startdate: startdate = CDate("21 aug 2011")
Dim enddate
'Get first day of month.
startdate = DateSerial(Year(startdate), Month(startdate), 1)
'Get last day of month.
enddate = DateAdd("m", 1, startdate) - 1
For day = startdate To enddate
If WeekDay(day) = vbThursday Then WScript.Echo day & " = " & WeekDayName(WeekDay(day))
Next
Output:
04/08/2011 = Thursday
11/08/2011 = Thursday
18/08/2011 = Thursday
25/08/2011 = Thursday
Any Date and Time constant can be used here to look for different or multiple weekdays with a little tinkering.