How to format calendar in moment js - date

I am trying to implement the momentjs calendar to show the date passed time as follow
moment("2016-11-13").calendar(moment("2016-11-13"),{
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'dddd MMM DD',
lastDay: '[Yesterday]',
lastWeek: '[Last] dddd',
sameElse: 'DD/MM/YYYY'
});
but my requirement is when there is days diff less than 7 days then it should show the day diff not "Last Monday"
please correct the format for nextDay, nextWeek, lastDay, lastWeek so that its show the days diff like 1 day ago

function getdateFormated (date){
var otherDates = moment(date).fromNow();
var calback= function () {
return '['+otherDates+']';
}
return moment(date).calendar(null,{
sameDay: '[Today]',
nextDay:calback,
nextWeek: calback,
lastDay: calback,
lastWeek: calback,
sameElse: 'MMM DD, YYYY'
});
}

Related

Date Picker is not disabling dates

I need to disable the first and third Wednesday in each month. The code I am using is below.This was working but when I added the new dates for 2021 it stopped working. Please help. Thanks
<script>
var dates = ["6-3-2019","20-3-2019","3-4-2019","17-4-2019","1-5-2019","15-5-2019","5-6-2019","19-6-2019","3-7-2019","17-7-2019","7-8-2019","21-8-2019","4-9-2019","18-9-2019","2-10-2019","16-10-2019","6-11-2019","20-11-2019","4-12-2019","18-12-2019","1-1-2020","15-1-2020","5-2-2020","19-2-2020","4-3-2020","18-3-2020","1-4-2020","15-4-2020","6-5-2020","20-5-2020","3-6-2020","17-6-2020","1-7-2020","15-7-2020","5-8-2020","19-8-2020","2-9-2020","16-9-2020","7-10-2020","21-10-2020","4-11-2020","18-11-2020","2-12-2020","16-12-2020","06-01-2021","20-01-2021","03-02-2021","17-02-2021","03-03-2021","17-03-2021","07-04-2021","21-04-2021","05-05-2021","19-05-2021","02-06-2021","16-06-2021","07-07-2021","21-07-2021","04-08-2021","18-08-2021","01-09-2021","15-09-2021","06-10-2021","20-10-2021","03-11-2021","17-11-2021","01-12-2021","15-12-2021"];
function DisableDates(date) {
var string = jQuery.datepicker.formatDate('dd/mm/yy', date);
return [dates.indexOf(string) == -1];
}
$(function() {
$("#datepicker2").datepicker({
beforeShowDay: DisableDates,
minDate: +1
});
});
</script>

Flatpickr multiple datepicker in same page

I realize a site in symfony and I use the flatpickr library for the selection of dates. that's what it's like now:
datepicker
So I have 2 datepicker who uses flatpickr which allows me to select a departure date with the time and a date back with the time too. My problem, when I select the first date, flatpickr shows me well the time selection but when I go on the second datepicker I can not select the time.
datepicker 1
datepicker 2
I wish I could select in the 2 inputs the date and the time.
Here is my JS code of my 2 inputs:
var departure = $('#quick_booking_departure');
var arrival = $('#quick_booking_arrival');
departure.flatpickr({
enableTime: true,
dateFormat: "Y-m-d H:i",
position: "above",
disableMobile: true,
locale: "fr",
minDate: "today",
onChange: function (selectedDates, dateStr, instance) {
arrival.flatpickr({
minDate: dateStr
});
departure.removeAttr('readonly');
arrival.removeAttr('readonly');
}
});
arrival.flatpickr({
enableTime: true,
dateFormat: "Y-m-d H:i",
position: "above",
disableMobile: true,
locale: "fr",
minDate: "today",
onChange: function (selectedDates, dateStr, instance) {
departure.flatpickr({
minDate: 'today'
});
departure.removeAttr('readonly');
arrival.removeAttr('readonly');
}
});
Thank you for your help.
It looks like your onChange function is the culprit adding enableTime: true allows time pick:
onChange: function(selectedDates, dateStr, instance) {
arrival.flatpickr({
enableTime: true,
minDate: dateStr
});
departure.removeAttr('readonly');
arrival.removeAttr('readonly');
}
But look closer, when one of your pickers change you are completely re-initializing the other. So all the options you originally defined are getting reverted back to default except for what you are re-defining minDate

MinDate and MaxDate are not working for the native date picker in Ionic 4

I am working in my Ionic 4 project and I have used the native date picker plugin. It is working fine but I am not able to set the min and max date in it for the Android.
This is my tab2.page.html:
<ion-input formControlName="startchallenge" placeholder="Select Date" (click)="datePickershow()" [readonly]=true></ion-input>
This is my tab2.page.ts:
datePickershow(){
this.datePicker.show({
date: new Date(),
mode: 'date',
androidTheme: this.datePicker.ANDROID_THEMES.THEME_HOLO_DARK,
minDate: new Date().toISOString(),
maxDate: new Date(new Date().setDate(new Date().getDate() + 10)).toISOString(),
}).then(
date => console.log('Got date: ', date)},
err => {
console.log('Error occurred while getting date: ', err)}
);
}
I have used min and max date in Android after that the user is able to select the back date from today because I have used the min date as a today date but the problem is that user is able to select the previous date in Android.
Any help is much appreciated.
Try This:
minDate: new Date().valueOf(),
maxDate: new Date(new Date().setDate(new Date().getDate() + 10)).valueOf(),
This will solve your problem.
I think you should use ion-datetime, which provide easiest way to getting date or time from user.
There are lots of methods to formate date and time input.

How To Disable Specific Days and Dates Using BeforeShowDay In jQueryUiDatepicker?

I already have functioning code in jQueryUiDatepicker that disables Fridays and Saturdays and all previous days (plus 2 days). My issue is trying to add 2 specific dates to this existing Datepicker code that will also disable these dates.
This is my existing code on starting line 92 in jQueryUiDatepicker:
beforeShowDay: function(date) {
var show = true;
if(date.getDay()==5||date.getDay()==6) show=false
return [show];
},
beforeShow: function(){
var dateTime = new Date();
var hour = dateTime.getHours();
//If Hour is greater or equals to 8AM
if(hour >= 08){
//Disable all past days including tomorrow and today
$(this).datepicker( "option", "minDate", "+2" );
}
},
I am trying to disable 18th and 19th October 2017 and failing, this is the code I have added directly underneath the above code:
beforeShowDay: var array = ['18/10/2017', '19/10/2017']
$('input').datepicker({
beforeShowDay: function(date){
var string = jQuery.datepicker.formatDate('dd/mm/yy', date);
return [ array.indexOf(string) == -1 ]
},
My question is how can I disable all previous dates, all Fridays and Saturdays and these 2 dates in the October?
Note# This coding has to be done in jquery.ui.datepicker, not a script in html
Hope this helps
use inArray instead of indexOf and you can also disable all previous dates using minDate
var array = ["18/10/2017", "19/10/2017"];
$(function() {
$('input').datepicker({
minDate: new Date(),
beforeShowDay: function (date) {
$thisDate = date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear();
var day = date.getDay();
if ($.inArray($thisDate, array) == -1&&day!=5&&day!=6) {
return [true, ""];
} else {
return [false, "", "Unavailable"];
}
}
});
});
DEMO

ionic2 datepicker current date

I am new to Ionic2.
Is there any way to display showing current date in ionic2 of datepicker ?? I mean current date won't show before datepicker's pick.It will only show only when datepicker apears. Thanks in advance.
Try mapping the datepicker model to a variable which holds the current date:
<ion-datetime [(ngModel)]="currentDate" /></ion-datetime
and in your controller:
var currentDate = new Date();
here's an example :
https://codesundar.com/ionic2-tutorial/ionic-2-date-picker-example/
<ion-datetime (ionChange)="changeDate()" displayFormat="MMMM YYYY" pickerFormat="MMMM YYYY" [(ngModel)]="filterdate"></ion-datetime>
and in your ts file
filterdate = this.today.toISOString();