In Rome, I would like to include multiple conditions, in my second calendar, that it would disallow dates that are earlier than today AND disallow dates that are earlier than what was chosen in first calendar.
var today = moment().format();
var startDate = rome(startDateElem, {dateValidator : rome.val.afterEq(today)});
var endDate = rome(endDateElem, {dateValidator : rome.val.afterEq([startDateElem,
today])});
I could specify default value to start date (today), but is there any other way?
your code should be like this:
var moment = rome.moment;
var today = moment().format();
var startDate = rome(startDateElem, {dateValidator : rome.val.afterEq(today)});
var endDate =rome(endDateElem, {dateValidator:function(d){
var m = moment(d);
var startD=rome(startDateElem).getDate();
if(startD){
return m.isAfter(today)&& m.isAfter(startD);
}else{
return m.isAfter(today)
} }
});
this a working demo that can help you
Related
How can I get the following codepen to default to showing all the data. I currently defaults to 21/11/2019 - 28/11/2019. If I change the range to 01/11/2019 - 30/11/2019 it shows all the data. I'm using lightpicker.js and moment.js. Thank you.
UPDATE: What I'm trying to do is show all the data with nothing in the Date Range. Just page defaulting to show everything with no filters. Then I should be able to filter if I choose dates in the Date Range. When I comment out the line picker.setDateRange(new Date(), moment().add(7, 'day')); It show blank text box for the Date Range but no data is shown.
JS
var picker = new Lightpick({
field: document.getElementById('datepickerA'),
singleDate: false
});
picker.setDateRange(new Date(), moment().add(7, 'day'));
$scope.onOkA = function(){
var startDate = picker.getStartDate().format('MM/DD/YYYY')
var endDate = picker.getEndDate().format('MM/DD/YYYY')
if(startDate && endDate){
$scope.filteredTicketA = $scope.ticketsA.filter(ele=>{
return (new Date(ele.Date)-new Date(startDate)>=0) && (new Date(ele.Date)-new Date(endDate)<=0)
})
}
}
new Date() will default to today, if you want it be 01/11/2019 then use new Date(2019,11-1, 1).
However I would use some constants to make code clearer, replace picker.setDateRange() sentence with these 3 lines:
var startDate = new Date(2019,11-1, 1); // be aware that month is 0 based.
var endDate = moment(startDate).endOf('month');
picker.setDateRange(startDate, endDate);
as a quick solution for onOKA(){} I would change this:
var defaultStartDate = moment(new Date(1, 10, 2019));
var startDate = (pickerB.getStartDate() || defaultStartDate).format('MM/DD/YYYY');
This question already has answers here:
How to enumerate dates between two dates in Moment
(9 answers)
Closed 2 years ago.
Get the date list based on start and end date using moment js.
For example, I have two dates, One is a start date and end date. My start date is 2019-04-02 and my end date is 2019-05-16 I need all the date in between these two dates.
My output will be ["2019-04-02", "2019-04-03", "2019-04-04", ..., "2019-05-16"] is it possible in moment js ?
This should work, but for the next time remember to add what you tried, before posting a question
var day1 = moment("2019-05-01");
var day2 = moment("2019-04-06");
var result = [moment({...day2})];
while(day1.date() != day2.date()){
day2.add(1, 'day');
result.push(moment({ ...day2 }));
}
console.log(result.map(x => x.format("YYYY-MM-DD")));
<script src="https://momentjs.com/downloads/moment.min.js"></script>
var dates = [];
var startDate = moment('2019-04-02', 'YYYY-MM-DD');
dates.push(startDate.format('YYYY-MM-DD'));
while(!startDate.isSame('2019-05-16')){
startDate = startDate.add(1, 'days');
dates.push(startDate.format('YYYY-MM-DD'));
}
console.log(dates);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>
Something like the following would work. We set our start and end date, create an empty array and loop through the days by adding a day per iteration, and adding the current day to our list.
var start = moment("2019-01-01")
var end = moment("2019-01-30");
var list = [];
for (var current = start; current <= end; current.add(1, 'd')) {
list.push(current.format("YYYY-MM-DD"))
}
var enumerateDaysBetweenDates = function(startDate, endDate) {
var dates = [];
var currDate = moment(startDate).startOf('day');
var lastDate = moment(endDate).startOf('day');
while(currDate.add(1, 'days').diff(lastDate) < 0) {
console.log(currDate.toDate());
dates.push(currDate.clone().toDate());
}
return dates;
};
Based on this Supplied Code,
$w.onReady(function () {
//TODO: write your page related code here...
const startFromDays = 4;
const endAtMonths = 9;
const today = new Date();
let startDate = new Date(today);
let endDate = new Date(today);
startDate.setDate(startDate.getDate() + startFromDays);
endDate.setMonth(endDate.getMonth() + endAtMonths);
$w.onReady(function () {
$w("#datePicker1").minDate = startDate;
$w("#datePicker2").maxDate = endDate;
});
});
I need help to find the difference between the endDate and the startDate and output it as Text. Knowing the fact that some start dates can be of the Eg: 26th of Feb and end Date can fall on 3rd March.
This Code is been run on Wixcode, where the dates are used as a Date-picker user input. Thank you.
Start by getting the difference between the two dates using something like what is described in this post.
Then, use that number to populate a text field that you've added to your page.
So, assuming you have a datediff() function declared:
const diff = datediff(startDate, endDate);
$w("#text1").text = diff.toString();
How to change the format of date range input component in pentaho cde.i am getting the format 'yyyy-mm-dd' but i need to change into 'dd-M-yy'.i have return a function under post execution section :
function()
{
var date1 = Dashboards.getParameterValue("parfromDate").toString();
var date2 = Dashboards.getParameterValue("partoDate").toString();
//alert(date1)
//alert(date2)
format = $.datepicker.formatDate("dd-M-yy",new Date(date1));
format2 = $.datepicker.formatDate("dd-M-yy",new Date(date2));
document.getElementById('render_SelectDate').value=format:format2;
}
the same function was working perfect in date input component but i m facing problem in date range component can any one suggest me where i m doing wrong ..
Finally i have solved my issue as per need .Also i have mentioned my script which i am using right now:
function f(){
var date1 = Dashboards.getParameterValue("date_param").toString();
testdate = $.datepicker.formatDate("d-M-y",new Date(date1));
//alert(testdate);
document.getElementById('render_date_picker').value=testdate;
}
**This code also work as charm for Date Range Component**
function f(){
var date1 = Dashboards.getParameterValue("param1_FromDate").toString();
var date2 = Dashboards.getParameterValue("param2_ToDate").toString();
testdate = $.datepicker.formatDate("d-M-y",new Date(date1))+">"+ $.datepicker.formatDate("d-M-y",new Date(date2));
alert(testdate);
document.getElementById('render_date_range_picker').value=testdate;
}
I have this code for calculating date difference (without weekends) between two input fields, and printing the difference in days in a third text box. The date format is yy-mm-dd (because of mysql).
<script type="text/javascript">
$("#vazi_od, #vazi_do").change(function() {
var d1 = $("#vazi_od").val();
var d2 = $("#vazi_do").val();
var minutes = 1000*60;
var hours = minutes*60;
var day = hours*24;
var vazi_od1 = getDateFromFormat(d1, "yy-mm-dd");
var vazi_do1 = getDateFromFormat(d2, "yy-mm-dd");
var newvazi_od=new Date();
newvazi_od.setFullYear(vazi_od1.getYear(),vazi_od1.getMonth(),vazi_od1.getDay());
var newvazi_do=new Date();
newvazi_do.setFullYear(vazi_do1.getYear(),vazi_do1.getMonth(),vazi_do1.getDay());
var days = calcBusinessDays(newvazi_od,newvazi_do);
if(days>0)
{ $("#razlika").val(days);}
else
{ $("#razlika").val(0);}
});
</script>
But, when i pick the start and the end date, nothing happens in the field that should show the difference in days... Any help?
You are using setFullYear to pass all the date params...
setFullYear is just for setting the year part of the date..
Use
var newvazi_od=new Date(vazi_od1.getYear(),vazi_od1.getMonth(),vazi_od1.getDay());
var var newvazi_do=new Date(vazi_do1.getYear(),vazi_do1.getMonth(),vazi_do1.getDay());
Also to use getDateFromFormat and calcBusinessDays you need to include the date library from the javascript toolbox