I want to disable Past dates in Kendo Date Picker. How can I do?
<kendo-datepicker [(value)]="oneTime.startDate" [disabled]="disableDates()"></kendo-datepicker>
disableDates() {
//return (this.currentDate.getTime() (new Date()).getTime());
}
<kendo-datepicker [(value)]="startDate" [disabledDates]="disabledDates"></kendo-datepicker>
public disabledDates = (date: Date): boolean => {
const yesterday = (d => new Date(d.setDate(d.getDate() - 1)))(new Date);
return (date.getTime() < yesterday.getTime());
};
Related
ion datetime isDateEnabled is not working. i already added isDateEnabled in HTML, but not working.
here is my code -
== HTML ==
<ion-datetime [isDateEnabled]="isDateEnabled('2022-06-26T00:00:00.000Z')" [firstDayOfWeek]="1" presentation="date" ></ion-datetime>
=== TS file ===
isDateEnabled(dateIsoString: string) {
const date = new Date(dateIsoString);
if (getYear(date) === 2022) {
return false;
}
return true;
}
I hope you have a good day. You need to pass a function in the isDateEnabled property
.html
<ion-datetime [isDateEnabled]="isDateEnabled"></ion-datetime>
.ts
// arrow function allow access global scope
isDateEnabled = (dateIsoString: string): boolean => {
return true;
};
I am working on a project for an Event application. My task is to create a partial view and show any events that are within the next two days.
I am getting an error:
Operator <= cannot be applied to operands of type string and DateTime
I am unsure how to fix this issue.
Here is my code:
public ActionResult GetLastMinuteDeals()
{
DateTime futureDate = DateTime.Today.AddDays(2);
var LastMinuteDeal = db.Events
.Where(a => a.EventStartDate <= DateTime.Today)
.Where(a => a.EventStartDate <= futureDate);
return LastMinuteDeal;
}
The member EventStartDate is likely a string type. To compare them to a DateTime, you will need to create another DateTime object, like so:
var LastMinuteDeal = db.Events
.Where(a => DateTime.Parse(a.EventStartDate) <= DateTime.Today)
.Where(a => DateTime.Parse(a.EventStartDate) <= futureDate);
I'm following a tutorial from here
For some reason when I try to create a new user with a date it won't accept it unless the month is January between dates ranging from 1-12ish.
I'm pretty sure it's because of the ValidationMessageFor(in the User.cs) method which forces me to enter a date which month must be January and I don't know where to alter it.
jquery.validate
jquery.validate.unobtrusive
Add code into script
$.validator.addMethod('date', function (value, element) {
if (this.optional(element)) {
return true;
}
var valid = true;
try {
$.datepicker.parseDate('dd/mm/yy', value);
}
catch (err) {
valid = false;
}
return valid;
});
$('#dt1').datepicker({ dateFormat: 'dd/mm/yy' });
If I have:
DatePicker dp = new DataPicker();
and at some point I want to know if the data is greater than today, how can I do it?
Example:
if I want to book a room in a hotel from 21/04/2014 well, it should be impossible because today is 28/07/2014.
How can I do it in JavaFX ?
To ensure that a given Date chosenDate is after today, you can check
if (chosenDate.after(new Date())) {
// valid (Date > today)
} else {
// invalid (Date <= today)
}
Note that chosenDate should be a Date with hour, minute and second set to 0 since else it could accept a Date with the same day as today but a later hour than now.
You can write a custom method, which will compare given dates of given date format, and return true, when current date is "older" than your date of interest, eg:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Demo {
public static void main(String args[]) {
System.out.println(isDateOfInterestValid("yyyy-mm-dd",
"2014-08-25", "2014-08-28"));
}
public static boolean isDateOfInterestValid(String dateformat,
String currentDate, String dateOfInterest) {
String format = dateformat;
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date cd = null; // current date
Date doi = null; // date of interest
try {
cd = sdf.parse(currentDate);
doi = sdf.parse(dateOfInterest);
} catch (ParseException e) {
e.printStackTrace();
}
long diff = cd.getTime() - doi.getTime();
int diffDays = (int) (diff / (24 * 1000 * 60 * 60));
if (diffDays > 0) {
return false;
} else {
return true;
}
}
}
And in context of pure JavaFX you can get the String value of DatePicker chosen date by calling DatePicker.getValue().toString().
PS In case You have only one DatePicker object, You can use "hidden" method, which will check the current date. It can look like this:
public static String currentDate(String separator) {
Calendar date = new GregorianCalendar();
String day = Integer.toString(date.get(Calendar.DAY_OF_MONTH));
String month = Integer.toString(date.get(Calendar.MONTH) + 1);
String year = Integer.toString(date.get(Calendar.YEAR));
if (month.length() < 2) {
month = "0" + month;
}
if (day.length() < 2) {
day = "0" + day;
}
String regDate = year + separator + month + separator + day;
return regDate;
}
I would like a lambda expression to get all my posts with a PublishDate in a specific month / year range (like 10/2011).
public IEnumerable<Post> SearchPosts(string periode)
{
// periode may be 10/2011 so I would like all posts from 10/01/2011 to 10/31/2011
return m_PostRepository.GetPosts().Where(x => x.PublishDate...?
}
Description
You can do this using the DateTime properties Year and Month in your Where Filter.
Sample
return m_PostRepository.GetPosts().Where(x => x.PublishDate.Year == 2011 &&
x.PublishDate.Month == 10).ToList();
More Information
MSDN - DateTime.Month Property
MSDN - DateTime.Year Property
Update after a comment from Bronzato
DateTime? date;
// does date has a value ? If yes, apply the filter. If not return everything.
if (date.HasValue)
{
return m_PostRepository.GetPosts().Where(x => x.PublishDate.Year == date.Value.Year &&
x.PublishDate.Month == date.Value.Month).ToList();
} else return return m_PostRepository.GetPosts();
You can also try it like this (working with PublishDate as Nullable<DateTime>):
DateTime date;
if (DateTime.TryParseExact(value, "MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
{
var result = m_PostRepository.GetPosts().Where(x => x.PublishDate.HasValue &&
x.PublishDate.Value.Month == date.Month &&
x.PublishDate.Value.Year == date.Year).ToList();
}
public IEnumerable<Post> SearchPosts(string periode){
string[] _periode = periode.Split("/");
return m_PostRepository.GetPosts().Where(x => x.PublishDate.year = convert.ToInt16(_periode[1])).Where(x => x.PublishDate.Month= convert.ToInt16(_periode[0]))}