I have two dates
1.statdate : 12-11-2022
2.enddate. : 02-20-2023
if the start date is 1-15th day then the result should be the current month ex: mm-dd-yyyy[12-11-2022] Then December 1st
if the start date is 16th-31st day then the result should be the current month EX: mm-dd-yyyy[12-22-2022] Then January 1st.
if the EndDate is 1-15th day then the result should be the current month+1 EX: mm-dd-yyyy[02-11-2022] Then January 31st
if the EndDate is 16-31sh day then the result should be the current month+1 EX: mm-dd-yyyy[02-20-2022] Then Feb 28th
input start date result: December 1st
input end date result: Feb 28th
Result[3] which is three months from the start date to the end date.
Can we do this in the formula field? I am able to do it in apex it worked but I was unable to do it in the formula field any help would be appreciated.
ROUND(((IF(DAY(Return_To_Work__c) <= 15, DATE( YEAR(Return_To_Work__c) ,
MONTH(Return_To_Work__c) -1,(DAY(Return_To_Work__c)-
DAY(Return_To_Work__c)+
28 + MOD(((MONTH(Return_To_Work__c) -1) +
FLOOR((MONTH(Return_To_Work__c) -1)/8)), 2) + MOD(2,
(MONTH(Return_To_Work__c) -1)) + 2 * FLOOR(1/(MONTH(Return_To_Work__c)
-1))))
,IF(DAY(Return_To_Work__c) >= 16,DATE( YEAR(Return_To_Work__c)
,MONTH(Return_To_Work__c),(DAY(Return_To_Work__c)-
DAY(Return_To_Work__c)+28 + MOD(((MONTH(Return_To_Work__c)) +
FLOOR((MONTH(Return_To_Work__c))/8)), 2) + MOD(2,
(MONTH(Return_To_Work__c))) + 2 *
FLOOR(1/(MONTH(Return_To_Work__c))))),NULL)) -
IF(DAY(First_Day_Of_Leave__c) <= 15, DATE( YEAR(First_Day_Of_Leave__c)
, MONTH(First_Day_Of_Leave__c) ,(DAY(First_Day_Of_Leave__c)-
DAY(First_Day_Of_Leave__c)+1)),IF(DAY(First_Day_Of_Leave__c) >=
16,DATE( YEAR(First_Day_Of_Leave__c)
,MONTH(First_Day_Of_Leave__c)+1,(DAY(First_Day_Of_Leave__c)-
DAY(First_Day_Of_Leave__c)+1)),NULL)))/30),0)
Related
I am making a Alarm System for Mon, Tue, Wed, Thu, Fri Sat and Sun separate. Let's say i am setting an alarm for Tuesday than i need all Tuesdays of current Month and atleast for current year till the alarm is Off. I want to achieve it using moment.
I am using Package - 'moment-weekdaysin', this is not giving me proper result. It is giving me incorrect date.
code - moment().weekdaysInMonth('Monday')
I've not used moment-weedaysin before but it should share most of the same API as core moment. The code below will capture all Tuesday dates in the format of Month-Day-Year (MM-DD-YYY) from the current date til the end of the current year. You can change the parameter for any other days 1-7 (Monday-Sunday).
import moment from 'moment';
const getOccurrencesOfDayThisYear = (day = 1) => {
let startDate = moment();
const endOfYear = moment().endOf('year');
const extractedDates = [];
while (startDate.isBefore(endOfYear)) {
if (moment(startDate).day() == day) {
extractedDates.push(moment(startDate).format('MM-DD-YYYY'));
}
startDate = moment(startDate).add(1, 'days');
}
return extractedDates;
};
// 2 represents Tuesday; 1 being Monday and 7 being Sunday
getOccurrencesOfDayThisYear(2)
There might be a more sophisticated way of performing this through various moment methods.
I have issue extracting week/year from DATE column.
We are in week 02 of 2022 and my goal is to set MAX week to be "01 2022" at the moment.
Goal is to have dynamic calculated column or measure that will always show previous week.
weekMax = FORMAT(MAX(fact[date]),"WW YYYY")
With this solution it is showing me 03 2022 result.
Is there a way to sort this out?
You could try something like:
weekMax =
VAR lastweek = FORMAT(DATEADD('Table'[Date].[Date], -7, DAY) ,"WW YYYY")
RETURN
IF(FORMAT(TODAY() - 7 ,"WW YYYY") = lastweek, lastweek, BLANK())
Output:
Or if you always just want the last week without considering any columns, you can use:
weekMax = FORMAT(TODAY() - 7 ,"WW YYYY")
As a little background: in October 1582 the Gregorian calendar was introduced to correct problems with the Julian calendar, which was in use until then. The Gregorian calendar specifies the length of a year more precisely, adds a new leap year calculation and removes 10 days from the Julian calendar on transition (moving from 4.Oct.1582 to 15.Oct.1582)
// Julian leap year calculation
((year % 4) == 0)
// Gregorian leap year calculation
((year % 4) == 0 && (year % 100) != 0) || (year % 400) == 0)
To sum up all calendar days from 1 AD to 2001 AD I use:
#include <stdio.h>
int main( void)
{
int year;
int daysInYear;
int total;
total = 0;
for( year = 1; year <= 2001; year++)
{
//
daysInYear = 365;
if( year < 1582)
daysInYear += ((year % 4) == 0);
else
if( year > 1582)
daysInYear += ((year % 4) == 0 && (year % 100) != 0) || ((year % 400) == 0);
else
daysInYear -= 10; // 1582 exactly
total += daysInYear;
printf( "%d: +%d = %d\n", year, daysInYear, total);
}
return( 0);
}
Now running this exhaustively over all years from 1 to 2000 gives this pastebin: https://pastebin.com/bR7hwNr1
The most interesting bits show that the leap year and day-skip calculation is correct and also produces the result:
1: +365 = 365
2: +365 = 730
3: +365 = 1095
4: +366 = 1461
...
100: +366 = 36525
...
400: +366 = 146100
...
1581: +365 = 577460
1582: +355 = 577815
1583: +365 = 578180
...
1900: +365 = 693962
...
1996: +366 = 729026
1997: +365 = 729391
1998: +365 = 729756
1999: +365 = 730121
2000: +366 = 730487
Now the question is this: the 1.1.2001 is at 730487 elapsed calendar days. Given the length of the year as defined by the Gregorian calendar as 365.2425, I would expect to see 2000*365.2425 = 730485 days. If one uses tropical days or solar days it would be 730484. But 740487 is clearly out of range.
Assuming that no-one miscounted any days in the Gregorian Calendar range, there are some extra days in the Julian Calendar, that don't match with the tropical days. But the Gregorian was created to correct the Julian calendar and I don't think they would have made that large an error in 1582.
This could be more a historical question than a programming question I would guess.
The goal of the Gregorian reform of the calendar was to reset the date of the northern hemisphere vernal equinox to March 21, and keep it there. This date was chosen because that was the approximate average date of the equinox at the time of the Council of Nicaea in AD 325. At the time of the council, the date of the equinox had slipped from about March 25 in AD 1.
For all the details read the book Gregorian Reform of the Calendar which is the proceedings of a conference held by the Vatican Observatory and published in 1983.
To clarify, when evaluating the Gregorian calendar compared to the Julian, using a mix of Julian and Gregorian dates incorporates the one-time correction of 10 days which was intended to correct for accumulated excess leap years from about AD 325 to AD 1582. If one wishes to use some start date other than AD 325, the entire calculation should use ONLY Gregorian dates or ONLY Julian dates.
I have a DayPickerInput element from react-day-picker plugin and I don't know how to disable all days after a month(31 days) starting with current day. Any help please?
Thanks.
The documentation could be a clearer. This should do it for you:
<DayPickerInput
value={moment(minDate).format('YYYY-MM-DD')}
dayPickerProps={{
disabledDays: {
after: new Date(2018, 3, 20),
},
}}
onDayChange={day => console.log(day)}
/>
Replace the new Date(y, m, d) with your date.
[Edit per my comment]
Not all months are 31 days, if you literally want to add 31 days to the first of a month:
Source: Add day(s) to a Date object
var myDate = new Date();
myDate.setDate(myDate.getDate() + AddDaysHere);
Where "AddDaysHere" would be 31.
If you just want to insure there is no way to select a date next month, you could:
// There is probably a billion better ways to get the next available month, this is just basic
let currentMonth = 2;
let nextMonth = currentMonth + 1;
if (nextMonth > 11) { nextMonth = 0;} // I believe javascript months start at 0.
Date(2018, nextMonth, 1)
Happy coding!
I am very new to angular JS but since morning struggling with this.
I have a datepicker with "MM/yyyy" format, the date value returned here is first day of month.
i.e. February 1, 2017 but i want the date as February 28, 2017 i.e last day of month.
Just to update i am using moment function.
Please suggest some work around for the same!
I infer from your question that you are using momentjs.
This lib provides you with a built in function endof
const date = new Date(2017, 1) // 1st Feb
moment(date).endOf('month');
This should handle most cases directly including leap years
If you have a JavaScript Date instance d, you can simply use
const d = new Date(2017, 1) // 1st Feb
d.setMonth(d.getMonth() + 1)
d.setDate(d.getDate() - 1)
console.info(d.toLocaleString())
Now d will be the last day of the month.
Note: this easily handles year boundaries without any extra code. For example
const d = new Date(2017, 11) // 1st Dec
console.info('Before', d.toLocaleString())
d.setMonth(d.getMonth() + 1)
d.setDate(d.getDate() - 1)
console.info('After', d.toLocaleString())
You just need add 1 month to the date, and then substract 1 day. Here's an example:
// Let's suppose the date selected from the picker was February 1st, 2017
// Remember months in JS are zero-index based, so 0=Jan, 1=Feb, etc.
var selectedDate = new Date(2017, 1, 1);
var month = selectedDate.getMonth();
var year = selectedDate.getFullYear();
month ++;
if(month > 11){ // Last month number is 11 (December)
month = 0; // January
year ++;
}
var oneMonthAheadDate = new Date(year, month, 1);
var lastDayOfSelectedMonthDate = new Date(oneMonthAheadDate.getTime() - (1000 * 3600 * 24)); // We substract 1 day (1000 ms x 3600 secs in an hour x 24 hours in a day)
Your needed date will be in lastDayOfSelectedMonthDate