I try to disabled the date for holidays and weekend but that not work
My code :
$(function() {
$('.thing12DatePicker').datepicker(
{
beforeShowDay: function (date) {
var startDate = "2017-06-17",
endDate = "2017-06-21",
dateRange = [];
for (var d = new Date(startDate); d <= new Date(endDate); d.setDate(d.getDate() + 1)) {
dateRange.push($.datepicker.formatDate('yy-mm-dd', d)&& $.datepicker.noWeekends);
}
var dateString = jQuery.datepicker.formatDate('yy-mm-dd', date);
return [dateRange.indexOf(dateString) == -1];
}
});
});
The date holidays are disabled but not the weekend !
I want disbled the weekend .
thx
I have found solution
var startDate = "2017-06-17",
endDate = "2017-06-21",
bankHoliDays = [];
for (var d = new Date(startDate); d <= new Date(endDate); d.setDate(d.getDate() + 1)){
bankHoliDays.push($.datepicker.formatDate('yy-mm-dd', d));
}
function disableDates(date) {
var dt = $.datepicker.formatDate('yy-mm-dd', date);
var noWeekend = jQuery.datepicker.noWeekends(date);
return noWeekend[0] ? (($.inArray(dt, bankHoliDays) < 0) ? [true] : [false]) : noWeekend;
}
$(function () {
$('#datepicker').datepicker({
beforeShowDay: disableDates
});
});
Related
I need to calculate the difference in days between two dates in two differente occasions
Occasion 1 - There's a start and an end date
Occasion 2 - There's a start date and a "IN PROGRESS" where the end date should be
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var daTa = ss.getSheetByName("Data");
var daysColumn = daTa.getRange('C2:C' + daTa.getLastRow()).getValues();
var startDate = daTa.getRange('C2:C'+ daTa.getLastRow()).getValues().flat();
var endDate = daTa.getRange('A2:A'+ daTa.getLastRow()).getValues().flat();
var today = new Date().valueOf();
endDate.forEach((finaldate,row) => {
if(finaldate == "IN PROGRESS") {
daysColumn[row][0] = (parseInt(startDate,10)-today);
} else {
daysColumn[row][0] = (parseInt(startDate,10)-parseInt(finaldate,10));
}})
daTa.getRange(2,4,daysColumn.length, 1).setValues(daysColumn)
}
Right now i got this bit of code, and it know what needs to be done, but it returns only "#NUM!" values on the column, where it should print the numbers.
Probably you want this:
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var daTa = ss.getSheetByName("Data");
var daysColumn = daTa.getRange('C2:C' + daTa.getLastRow()).getValues();
var startDate = daTa.getRange('C2:C' + daTa.getLastRow()).getValues().flat()
.map(x => new Date(x).valueOf()); // get milliseconds of the dates
var endDate = daTa.getRange('A2:A' + daTa.getLastRow()).getValues().flat()
.map(x => new Date(x).valueOf()); // get milliseconds of the dates
var today = new Date().valueOf();
var day = 1000 * 60 * 60 * 24; // milliseconds in a day
endDate.forEach((finaldate, row) => {
if (finaldate == "IN PROGRESS") {
daysColumn[row][0] = (startDate[row] - today) / day;
} else {
daysColumn[row][0] = (startDate[row] - finaldate) / day;
}
})
daTa.getRange(2, 4, daysColumn.length, 1).setValues(daysColumn)
}
function DiffInDays(Day1,Day2) {
if(Day1 && Day2 && (Object.prototype.toString.call(Day1) === '[object Date]') && (Object.prototype.toString.call(Day2) === '[object Date]')) {
var day=86400000;
var t1=new Date(Day1).valueOf();
var t2=new Date(Day2).valueOf();
var d=Math.abs(t2-t1);
var days=Math.floor(d/day);
//Logger.log(days);
return days;
} else {
throw 'Invalid Inputs';
}
}
can someone help me figure what's wrong with my logic?, i'm new using google script app and stuck around a week and got this error
Error message:
TypeError: d1.getTime is not a function (inDays)
var DateDiff = {
inDays: function(d1, d2) {
var t2 = d2.getTime();
var t1 = d1.getTime();
Logger.log("t1" + t1)
return parseInt((t2-t1)/(24*3600*1000)+1);
}
}
var dateStr = data[m][xMonth].toString() // the value here is =>1/10/2022
var todayDate = new Date();
if(dateStr.toString().includes('/')){
var yearA = '20'+dateStr.substring(6, 8)
var monthA = +dateStr.substring(3, 5)
if(monthA.toString() != '11' || monthA.toString() != '12') monthA = '0'+monthA
var dayA = +dateStr.substring(0, 2)
var tempDate = yearA + monthA + dayA
var Ryear = +tempDate.substring(0, 4)
var Rmonth = +tempDate.substring(4, 6)
var Rday = +tempDate.substring(6, 8)
var newDate = new Date(Ryear, Rmonth - 1, Rday)//because month start from 0
var realDueDate = DateDiff.inDays(todayDate, newDate) // error here in var newDate
}
Try this:
function myFunk() {
const D2 = new Date();
const D1 = new Date(D2.getFullYear(),D2.getMonth() - 2,D2.getDate());
var DateDiff = {
d1:D1,d2:D2,
inDays: function () {
let t2 = this.d2.getTime();
let t1 = this.d1.getTime();
return parseInt((t2 - t1) / (24 * 3600 * 1000) + 1);
}
}
Logger.log(DateDiff.inDays());
}
Execution log
10:58:41 AM Notice Execution started
10:58:39 AM Info 62.0
10:58:41 AM Notice Execution completed
I have code snippet below for grouping records for last 12 months and it works properly but I just noticed that empty months is not included. Where did I go wrong?
Thanks in advance
public IQueryable<DashboardGrouping> DashboardStats()
{
var yearAgo = DateTime.Now.AddYears(-1);
var date = new DateTime(yearAgo.Year, yearAgo.Month, 1);
var items = context.Set<Transaction>()
.Where(x => x.IsActive &&
x.CreatedAt.HasValue && x.CreatedAt.Value.Date >= date.Date && x.PaymentStatusId ==
PaymentStatus.Completed)
.Include(x => x.Payment)
.Include(x => x.Branch)
.AsNoTracking()
.Select(x => new
{
Year = x.CreatedAt.Value.Year,
Month = x.CreatedAt.Value.Month,
CashAmount = x.Payment.CashAmount,
CardAmount = x.Payment.CardAmount,
})
.GroupBy(x => new
{
Year = x.Year,
Month = x.Month,
})
.Select(x => new DashboardGrouping
{
Year = x.Key.Year,
Month = x.Key.Month,
TotalSale = x.Sum(s => s.CashAmount + s.CardAmount)
});
return items;
}
You can do client-side postprocessing and enrich result with missing records.
Helper function for generating months:
static IEnumerable<DateTime> GetMonths(DateTime startDate, DateTime endDate)
{
startDate = new DateTime(startDate.Year, startDate.Month, 1);
endDate = new DateTime(endDate.Year, endDate.Month, 1);
while (startDate < endDate)
{
yield return startDate;
startDate = startDate.AddMonths(1);
}
}
Postprocessing:
var currentDate = DateTime.Now;
var yearAgo = currentDate.AddYears(-1);
var months = GetMonths(yearAgo, currentDate);
var stats = DashboardStats().ToList();
// left join months to actual data
var query =
from m in months
join s in stats on new { m.Year, m.Month } equals new { s.Year, s.Month } into gj
from s in gj.DefaultIfEmpty()
select s ?? new DashboardGrouping
{
Year = m.Year,
Month = m.Month,
TotalSale = 0
};
var result = query.ToList();
I'm trying to disable the weekends (saturdays and sundays) and some dates (like '2018-05-11', '2018-05-21', '2018-05-24', etc.) in MaterializeCSS datepicker, but I want to disable those dates every year. I'm able to disable the days and dates with
$('.datepicker').pickadate({
disable: [
1, 7, new Date(2018,5,11), {from: [2018,5,11], to: [2018,5,22]}, {from: [2018,8,5], to: [2018,8,17]}
]
});
So I want to know if there's a way to made it repeat every year.
materializecss pickers
You can customize which days are disabled with the disableDayFn option when initializing the datepicker. This CodePen shows an example of the disableDayFn option being used to disable weekends, May 11th, 21st, and 24th of every year.
$('.disablePast').pickadate({
selectMonths: true, // Creates a dropdown to control month
selectYears: 105, // Creates a dropdown of 15 years to control year,
today: 'Today',
clear: 'Clear',
close: 'Ok',
format : 'dd/mm/yyyy',
closeOnSelect: true,
min : true
});
$('.datepicker').pickadate({
selectMonths: true, // Creates a dropdown to control month
selectYears: 105, // Creates a dropdown of 15 years to control year,
today: 'Today',
clear: 'Clear',
close: 'Ok',
format : 'dd/mm/yyyy',
closeOnSelect: true,
onSet: function(context) {
var id = this.$node[0].id;
var d = new Date(context.select);
var dd = d.getDate();
var mm = d.getMonth()+1; //January is 0!
var yyyy = '';
yyyy = new Date().getFullYear();
year1=yyyy;
month1=mm;
if(dd<10){
dd='0'+dd;
}
if(mm<10){
mm='0'+mm;
}
var df = mm+'/'+dd+'/'+yyyy;
var msec = Date.parse(df);
var d1 = new Date();
var d2 = new Date(msec);
var timeDiff = d2.getTime() - d1.getTime();
var DaysDiff = timeDiff / (1000 * 3600 * 24);
var dff = '';
var dft = '';
if(DaysDiff >= 0){
dff = dd+'/'+mm+'/'+yyyy;
} else{
yyyy = yyyy + 1;
dff = dd+'/'+mm+'/'+yyyy;
}
if(month1==1)
{
year1 = year1 - 1;
month1 = 12;
}
else if(month1<=10)
{
month1=month1-1;
month1='0'+month1;
}
else
{
month1=month1-1;
}
dft = dd+'/'+month1+'/'+year1;
/*if(df > 0){
dft = dd+'/'+mm+'/'+yyyy;
}
// if(mm = 01) {
// mm = 12;
// yyyy = yyyy - 1;
// dft = dd+'/'+mm+'/'+yyyy;
// }
else{
yyyy = yyyy + 1;
mm = mm - 1;
dft = dd+'/'+mm+'/'+yyyy;
}*/
console.log(dft);
if(id == 'dob')
$('#dob_rem_on').val(dff);
if(id == 'aniv_date')
$('#aniv_rem_on').val(dff);
if(id == 'passport_ren')
$('#pass_rem_on').val(dft);
if(id == 'insurance_ren')
$('#insurance_rem_on').val(dft);
if(id == 'life_insurance_ren')
$('#life_insurance_rem_on').val(dft);
Materialize.updateTextFields();
}
});
I'm trying to make the datepicker disable 1 week from the current date.
The code is for a datepicker for room reservation using an onRender function.
Please help me :(
$(function() {
var nowTemp = new Date();
var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);
var checkin = $('#ad').datepicker({
onRender: function(date) {
return date.valueOf() < now.valueOf() ? 'disabled' : '';
}
}).on('changeDate', function(ev) {
if (ev.date.valueOf() > checkout.date.valueOf()) {
var newDate = new Date(ev.date)
newDate.setDate(newDate.getDate() + 1);
checkout.setValue(newDate);
}
checkin.hide();
$('#dpd2')[0].focus();
}).data('datepicker');
var checkout = $('#dd').datepicker({
onRender: function(date) {
return date.valueOf() <= checkin.date.valueOf() ? 'disabled' : '';
}
}).on('changeDate', function(ev) {
checkout.hide();
}).data('datepicker');
});