Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8001339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:04:12+00:00 2026-06-04T16:04:12+00:00

I have two datetime values and i dont knw how to compare them. I

  • 0

I have two datetime values and i dont knw how to compare them. I know if i had only date values then before() and after() methods would have worked but i have no idea about Datetime values. All i have done is below plz tell me if its correct ?? and plz do guide me if its not a good way and a better alternative is available.

Date now = new Date();
DateTime currenttime = new DateTime(now, TimeZone.getTimeZone("IST"));
DateTime edate = e.getEnd().getDateTime();                 
if(currenttime.getValue()>edate.getValue())
{
       //here I want to do the logic to delete this event.         
}

e refers to the event object that is of google calendar. All i want to do here is check if Event e is past todays date and time. and if it is then i wanna delete the event.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:04:13+00:00Added an answer on June 4, 2026 at 4:04 pm

    You can use jdk Calendar to get and check days:

    public boolean isDatePass(Date date) {
        Calendar calendar = Calendar.getInstance();
    
        // Getting day of year and year of checked date:
        calendar.setTime(date);
        int checkedYear = calendar.get(Calendar.YEAR);
        int checkedDay = calendar.get(Calendar.DAY_OF_YEAR);
    
        // Getting day of year and year of current date:
        calendar.setTime(new Date());
        int currentYear = calendar.get(Calendar.YEAR);
        int currentDay = calendar.get(Calendar.DAY_OF_YEAR);
    
        if(checkedYear != currentYear) {
            return checkedYear < currentYear;
        }
    
        return checkedDay < currentDay;
    
    }
    

    For yoda DateTime:

    public boolean isDatePass(DateTime date) {
        // Getting day of year and year of checked date:
        int checkedYear = date.getYear();
        int checkedDay = date.getDayOfYear();
    
        // Getting day of year and year of current date:
        DateTime currentTime = new DateTime(now, TimeZone.getTimeZone("IST"));
        int currentYear = currentTime.getYear();
        int currentDay = currentTime.getDayOfYear();
    
        if(checkedYear != currentYear) {
            return checkedYear < currentYear;
        }
    
        return checkedDay < currentDay;
    
    }
    

    Not days only but time:

    public boolean isDatePass(DateTime date) {
    
        DateTime currentTime = new DateTime(now, TimeZone.getTimeZone("IST"));
        return date.isAfter(currentTime);
    }
    

    More simple solution (according to javadoc when pass null to isAfter/isBefore this mean current or now):

    public boolean isDatePass(DateTime date) {
        return date.isAfter(null); // but it does not take in account time zone
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem. I am trying to compare two datetime values in
I need to compare two datetime values to determine equality(exactly the same),using minute precision.Would
Suppose you have two datetime values, date_a and date_b What expression evaluates to true
How do I subtract two DateTime values from another DateTime value and have the
I have two Classes which are made up of two DateTime values. A start
I have a table called Sessions with two datetime columns: start and end. For
Say I have these two DateTime objects: var dt1 = new DateTime(1900,12,1,1,1,1); var dt2
I have two DateTime variables first period and second period and with each period
I have two tables user_raters: | id(int) | to_id(int) | value(int) | created_at(datetime) |1
I have two List which I am accessing by index (e.g. Name[10] , Date[10]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.