Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check date with todays date

Tags:

java

date

android

I have written some code to check two dates, a start date and an end date. If the end date is before the start date, it will give a prompt that says the end date is before start date.

I also want to add a check for if the start date is before today (today as in the day of which the user uses the application) How would I do this? ( Date checker code below, also all this is written for android if that has any bearing)

if (startYear > endYear) {     fill = fill + 1;     message = message + "End Date is Before Start Date" + "\n"; } else if (startMonth > endMonth && startYear >= endYear) {     fill = fill + 1;     message = message + "End Date is Before Start Date" + "\n"; } else if (startDay > endDay && startMonth >= endMonth && startYear >= endYear) {     fill = fill + 1;     message = message + "End Date is Before Start Date" + "\n"; } 
like image 911
Zaask Avatar asked Jun 30 '11 15:06

Zaask


People also ask

How do I validate a date today?

To check if a date is today's date:Use the toDateString() method to compare the two dates. If the method returns 2 equal strings, the date is today's date.

How can I compare today's date with another date in PHP?

Once you have created your DateTime objects, you can also call the diff() method on one object and pass it the other date in order to calculate the difference between the dates. This will give you back a DateInterval object. $last = new DateTime( "25 Dec 2020" ); $now = new DateTime( "now" );

How do you check if a string is a date in JavaScript?

Using the Date. One way to check if a string is date string with JavaScript is to use the Date. parse method. Date. parse returns a timestamp in milliseconds if the string is a valid date.


1 Answers

Don't complicate it that much. Use this easy way. Import DateUtils java class and call the following methods which returns a boolean.

DateUtils.isSameDay(date1,date2); DateUtils.isSameDay(calender1,calender2); DateUtils.isToday(date1); 

For more info refer this article DateUtils Java

like image 101
Kishath Avatar answered Sep 18 '22 11:09

Kishath