How to format min and max date in Laravel In my Laravel-5.8, I ham using JQuery datepicker
<script>
$(document).ready(function () {
$('.leaveDate').datetimepicker({
format: 'MM/DD/YYYY',
locale: 'en'
});
<script>
$(document).ready(function () {
$('.dobDate').datetimepicker({
format: 'MM/DD/YYYY',
locale: 'en'
});
</script>
How do I format
For leaveDate: the minimum date to be 1st day of the current year (users cannot select before 1st day of the current year) and maximum date to be last day of the current year(user cannot select after last after last day of the current year)
for dobDate: users cannot select future date
Thanks
You should use minDate and maxDate.
Here is the documentation for jQuery date time picker: https://xdsoft.net/jqplugins/datetimepicker/#mindate if that's the one you use.
$('.leaveDate').datetimepicker({
format: 'MM/DD/YYYY',
locale: 'en',
minDate: '2020/01/01',
maxDate: '2020/12/31'
});
$('.dobDate').datetimepicker({
format: 'MM/DD/YYYY',
locale: 'en',
maxDate: (new Date()).toString()
});
I don't know which exactly plugin you use, but in this one you can set startDate and endDate
https://www.daterangepicker.com/
In pure js
new Date(new Date().getFullYear(), 0, 1); // first day of current year
new Date(new Date().getFullYear(), 11, 31); // last day of current year
new Date(); // current day so it's max date
Or you cas use https://momentjs.com/ which is similar to Carbon but in js world
Not a Laravel Question. Try this;
<script>
$(document).ready(function () {
$('.leaveDate').datetimepicker({
format: 'MM/DD/YYYY',
changeYear: false,
locale: 'en'
});
$('.dobDate').datetimepicker({
format: 'MM/DD/YYYY',
maxDate:0,
locale: 'en'
});
});
Current year is most easily accomplished by not letting the user change the year
DOB is most easily accomplished as an offset 0 days from today.
Both are theoretical based on reading the API
https://api.jqueryui.com/datepicker/#option-maxDate
Please sign in or create an account to participate in this conversation.