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!
Related
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")
I have a format which returns me some dates and I need to parse it into something else which I find a little bit complicated.
The data format is Mon Dec 24 2018 9:00:00 as a startDate for example and Friday Dec 28 2018 17:00:00 as an endTime for example. What happens here is that I select I want someone to start on Monday at 9 until 17 everyday, but what my data does is makes it look like he's working non-stop.
I have tried mapping over it and putting it onto objects with days of the week and start and end times, but I ran into a problem because I create the object like
dates : {
monday: {
start: 9:00,
end: 18:00
},
tuesday: {
start:9:00,
end:18:00
}
// etc for everyday of the week
}
But, what if I only need Monday through Thursday, for example, that would be a problem. Anyone has any idea, how could I do that, in any other way? I was thinking about using moment.js.
I'm not sure if I understand your question, but I think you want to list all days between two different dates, here is an example of function that iterates over days by using moment.isSameOrBefore and moment.add functions, hope this help:
function toDays(startDateString, endDateString) {
const startDate = moment(startDateString, 'dddd MMM DD YYYY');
const endDate = moment(endDateString, 'dddd MMM DD YYYY');
const dates = {};
while(startDate.isSameOrBefore(endDate, 'day')) {
const currentDay = startDate.format('dddd');
dates[currentDay] = {start:'9:00', end:'18:00'};
startDate.add(1, 'days');
}
return dates;
}
const result = toDays('Monday Dec 24 2018', 'Friday Dec 28 2018');
console.log(result);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment.min.js"></script>
I'm doing a service chat and I'd like to extract days that correspond to Sunday. For exemple:
Watson: Choose a date
user: day 30
Watson: We don't open this day, because it's a Sunday.
The problem is.. the Sundays of this month are not the same as next month.. I tried with an array inside the context with Sundays days of this month(ex: "2","9","16","23","30"), but the Conversation didn't understand that day 30 is a Sunday.. Could anyone help me please?
Tks! :)
In this case, unfortunally, #sys-date does not work equal #sys-number.
In this case with #sys-number, if user type 1, #sys-number recognize and can use #sys-number:1 with condition inside the flow.
Unfortunally, #sys-date doesn't.
In this case, for get the date with javascript you can use:
new Date() //get the date NOW
new Date(milliseconds)
new Date(dateString)
new Date(year, month, day, hours, minutes, seconds, milliseconds)
You can see the now() is the same format to get date:
new Date(year, month, day, hours, minutes, seconds, milliseconds)
And you can convert the #sys-date to the same format, and use this to verify the name of the date.
Get the day with context variable and use code in your application. For example:
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var dateObject = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]);
var dayName = days[dateObject.getDay()];
console.log(dayName);
And make some condition... for example:
if(dayName === 'Sunday'){
data.output.text[0] = "We don't open this day, because it's a Sunday."
}
I code this and works fine, see:
function dayRequest(data, req, res){
console.log('works the true condition context')
var dateString = data.context.day; //context variable with <? #sys-date ?>
var dateParts = dateString.split("/");
var dateObject = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]);
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var dateObject = new Date(dateParts[2], dateParts[1] - 1, dateParts[0]);
var dayName = days[dateObject.getDay()];
console.log(dayName);
if(dayName === 'Sunday'){
data.output.text[0] = "We don't open this day, because it's a Sunday.";
return res.json(data);
}
}
Check my app:
In this case, you can use now to get the date and in your application you'll end a message if the day is Sunday... You can use context variable for this too, but, you need set all dates.. And with this code, you'll check the date and your application will send a message.
Summary: convert your #sys-date to the same format now() and use my code to send a message for your user if the day is Sunday. I created one context variable with to save the date after request and in the next flow I create one context with dayTrue: true inside conversation flow. In my application, I created one condition in my updateMessage() if data.context.date === true, my function dayRequest() will execute.
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
I am fetching the date from my Django backend which comes like this: 2016-03-31
In my angular controller I want to compare it with today's date and if they are similar I want to deactivate a button.
I tried new Date() which gives me something like Thu Mar 31 2016 08:59:01 GMT+0200 (W. Europe Daylight Time)
How can these two dates be compared to achieve my goal?
ehhhhh... i think currently we could only do a manual formatting
see this one: How to format a JavaScript date
For your reference, below is what i did though:
$scope.formatDate = function(date){
var newDate = new Date(date);
var year = newDate.getFullYear();
var month = (newDate.getMonth() + 1).toString(); //add 1 as Jan is '0'
var day = newDate.getDate().toString();
month = month.length > 1? month: '0'+month;
day = day.length > 1? day: '0'+day;
$scope.date = day + '/' + month + '/' + year;
}
If you want to compare the date with now you can do the following:
var now = new Date().getTime();
var compareDate = new Date('2016-03-31').getTime();
if(now > compareDate){
//greater
}else if(now < compareDate){
//less
}else{
//equal
}
Just add what you need to the scope and then you could do something like:
ng-disabled="compareDate === today"