Horje
javascript max date Code Example
javascript maximum date
let Maximum = new Date(8640000000000000);
let Minimum = new Date(-8640000000000000);
javascript maximum date
let maxDate = new Date(8640000000000000);
let minDate = new Date(-8640000000000000);

console.log(new Date(maxDate.getTime()).toString());
console.log(new Date(maxDate.getTime() - 1).toString());
console.log(new Date(maxDate.getTime() + 1).toString()); // Invalid Date

console.log(new Date(minDate.getTime()).toString());
console.log(new Date(minDate.getTime() + 1).toString());
console.log(new Date(minDate.getTime() - 1).toString()); // Invalid Date
javascript max date
<input type="datetime" name="" id="date">


<script src="/js/moment.js"></script>
<script>
var date = new Date();

var futuredate = new Date();
var notAllowedDay = date.getDate();
var tdate = date.getDate() + 1;
var month = date.getMonth() + 1;
// future date
var maxMonth = futuredate.getMonth() + 1;

var maxYear = date.getUTCFullYear();
var year = date.getUTCFullYear();

if (tdate < 10) tdate = "0" + tdate;
if (month < 10) {
  month = "0" + month;
}
var getDaysInMonth = function (maxMonth, maxYear) {
  return new Date(maxYear, maxMonth, 0).getDate();
};
const daysmonth = getDaysInMonth(maxMonth, maxYear);

var maxTdate = futuredate.getDate() + daysmonth;

if (maxTdate < 10) maxTdate = "0" + maxTdate;
if (maxMonth < 10) {
  maxMonth = "0" + maxMonth;
}


// for minimum rage
const meanDate = year + "-" + month + "-" + tdate;
const notAllowed = year+"-"+month+"-"+notAllowedDay;
console.log(daysmonth);
console.log(`Today is ${notAllowed}`)
const maxDate = maxYear + "-" + maxMonth + "-" + daysmonth;
console.log(date.toLocaleDateString());
console.log(maxDate);
document.getElementById("date").setAttribute("min", meanDate);




// for the max date


const m = moment();
const curM = m.toISOString();
const currentMoment = moment().subtract(0, 'days');
const endMoment = moment().add(3, 'days');
currentMoment.add(30, 'days');
let naNow = currentMoment.format('YYYY-MM-DD')
    console.log(`Loop at ${naNow}`);
document.getElementById("date").setAttribute("max", naNow);

</script>




Javascript

Related
firestore save a score as a number not a string in js Code Example firestore save a score as a number not a string in js Code Example
get selected value of select2 dropdown in jquery Code Example get selected value of select2 dropdown in jquery Code Example
build a javascript to easily change website colours theme Code Example build a javascript to easily change website colours theme Code Example
parsley validation checkbox alignment Code Example parsley validation checkbox alignment Code Example
Logical Assignment Operator null coalescing Code Example Logical Assignment Operator null coalescing Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7