I try to get current year in calendar.. now year is 2016 so i don't want past years and future years only want current year ... and also month is June or any other month so i don't future months only want current and past months . when year 2017 then in calendar must be year 2017 ..when month is June or any other month then not able to select future months .. we only select only current month and past months according to year
e,g, current month is June so
Jan 2016.... June 2016
this is what i try but this always show past and future months /years/days
<script type="text/javascript">
$(function() {
var currentYear = (new Date).getFullYear();
var currentMonth = (new Date).getMonth();
var currentDay = (new Date).getDate();
$('#fromdate').shieldDatePicker({
minDate: new Date((currentYear - 1), 12, 1),
//minDate: 0,
dateFormat: 'yy-mm-dd',
maxDate: new Date(currentYear, currentMonth, currentDay),
//maxDate: new Date((currentYear + 1), 12, 1),
onSelect: function(selectedDate) {
// Start Date
var startDate = $(this).shieldDatePicker('getDate');
$('#todate').shieldDatePicker('option', 'minDate', startDate);
$('#todate').shieldDatePicker('setDate', startDate);
// End Date
var enddate = $(this).shieldDatePicker('getDate');
enddate.setDate(enddate.getDate()+ 7);
$('#todate').shieldDatePicker('option', 'maxDate', enddate);
}});
$('#todate').shieldDatePicker({
minDate: new Date((currentYear - 1), 12, 1),
minDate: 0,
dateFormat: 'yy-mm-dd',
maxDate: '+7'
});
});
</script>
You can use the min and max values to set the dates.
This is demonstrated in the following snippet:
http://jsbin.com/vixiqo/3/edit?html,output
The calendar is restricted to the current year.
Related
I am trying to create a feature where I can transfer money by scheduling, so for that, I need a recurring option for the month and weak, And the problem that I face is, that if a user chooses the 31st of a month every month doesn't have the 31st, so the transaction should happen in that particular month's end date.
for example: If I start recurring date is 31st May 2022
no of transactions: 3
Current Output: Dates of transactions => 1st July 2022, 31st July 2022, 31st August 2022,
Correct Output: 30th June 2022, 31st July 2022, 31st August 2022,
Maybe something like I proposed here:
With lastDayOfMonth you could potentially do something like
extension AddMonth on DateTime {
DateTime addMonths([int amount = 1]) {
final plusXMonths = DateTime(year, month + amount, day);
final xMonthsAhead = DateTime(year, month + amount);
if (xMonthsAhead.lastDayOfMonth.compareTo(plusXMonths).isNegative) {
return xMonthsAhead.lastDayOfMonth;
} else {
return plusXMonths;
}
}
}
This proposition is based on this code that I created a PR for:
extension DateTimeLastFirstDay on DateTime {
/// Returns the Monday of this week
DateTime get firstDayOfWeek =>
isUtc ? DateTime.utc(year, month, day + 1 - weekday) : DateTime(year, month, day + 1 - weekday);
/// Returns the Sunday of this week
DateTime get lastDayOfWeek =>
isUtc ? DateTime.utc(year, month, day + 7 - weekday) : DateTime(year, month, day + 7 - weekday);
/// Returns the first day of this month
DateTime get firstDayOfMonth => isUtc ? DateTime.utc(year, month, 1) : DateTime(year, month, 1);
/// Returns the last day of this month (considers leap years)
DateTime get lastDayOfMonth => isUtc ? DateTime.utc(year, month + 1, 0) : DateTime(year, month + 1, 0);
/// Returns the first day of this year
DateTime get firstDayOfYear => isUtc ? DateTime.utc(year, 1, 1) : DateTime(year, 1, 1);
/// Returns the last day of this year
DateTime get lastDayOfYear => isUtc ? DateTime.utc(year, 12, 31) : DateTime(year, 12, 31);
}
Using the time package you could create a similar code for weeks.
How can i exclude weekends from min/max date calculation ?
Example : if the date is 15 oct , i can select only 5, 6 9, or 10 nov.
beforeShowDay: $.datepicker.noWeekends,
minDate: "+14D",
maxDate: "+19D",
I am working in my Ionic 4 app and I have used a native datepicker for that and I am converting the date to toISOString() but the problem is that it is showing one day before.
This is my ts:
this.datePicker.show({
date: new Date(),
mode: 'date',
androidTheme: this.datePicker.ANDROID_THEMES.THEME_HOLO_DARK,
}).then(
date => {
me.acceptchallengeform.setValue({
startchallenge: new Date(date).toISOString().split('T')[0],
});
console.log('Got date: ', date)},
err => {
console.log('Error occurred while getting date: ', err)}
);
var DatePickerDate ='Thu Aug 09 2018 00:00:00 GMT+0100 (British Summer Time)';
var myDate = new Date(DatePickerDate).toISOString().split('T')[0];
so myDate is now 2018-08-08
The problem is that it is showing the date one day before.
But I want to show the exact selected date.
Any help is much appreciated.
new Date() return the date using your system timezone.
toISOString() return the date in UTC and the time part of your date is midnight, so it returns Thu Aug 08 2018 23:00:00 (BST - 1h), that's why you're getting one day before.
What are your trying to do exactly?
Editing my answer following comment
in your case I would choose the easy way as you apparently don't need any timezone information:
startchallenge: date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
or you can use moment.js (http://momentjs.com/docs/#/displaying/format/)
Try This:
date = new Date(date.setDate(date.getDate() + 1));
me.acceptchallengeform.setValue({
startchallenge: new Date(date).toISOString().split('T')[0],
});
This will solve your problem.
I want to run a trigger at specific date and time (+or - 15 min).
I have a date min string with YYYY-MM-DD HH:MM format say 2017-04-01 18:05 How will I modify the below script to run at 18 hours and 5 minutes.
var triggerDay = new Date(2017, 04, 01);
ScriptApp.newTrigger("myFunction")
.timeBased()
.at(triggerDay)
.create();
You can try this:
function createTimeDrivenTriggers() {
// Trigger on 2017-04-01 around 18:00 (±15 min).
ScriptApp.newTrigger('myFunction')
.timeBased()
.atDate(2017, 04, 01)
.atHour(18)
.create();
}
https://developers.google.com/apps-script/reference/script/clock-trigger-builder
// the full Date constructor is:
// new Date( year, month, day, hour, min, sec, ms )
var triggerDay = new Date(2017, 3, 01, 18, 5);
ScriptApp.newTrigger("myFunction")
.timeBased()
.at(triggerDay)
.create();
I'm pretty sure that the month in the constructor is zero-based (January==0), so, I changed the 04 to a 3.
Try to limit the date selection between today and 31st Dec of next year.
$(function() {
$('.public-holiday-date-pick').datepicker({
minDate: '0',
yearRange: '-0:+1',
maxDate: ???
hideIfNoPrevNext: true
});
});
How should I define maxDate ? tried few things like '31 12 +1', or just 'last day of next year', did not work.
1) First get today's using
var today = new Date();
2) Similarly set the lastDate as below
var lastDate = new Date(today.getFullYear() +1, 11, 31);
The value in lastDate will be like
lastDate = 31 December, today's year +1
Finally set the lastDate as maxDate
var today = new Date(); //Get today's date
var lastDate = new Date(today.getFullYear() +1, 11, 31); //To get the 31st Dec of next year
$(function() {
$('.public-holiday-date-pick').datepicker({
minDate: '0',
yearRange: '-0:+1',
maxDate: lastDate, //set the lastDate as maxDate
hideIfNoPrevNext: true
});
});
JSFiddle