Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: comparison between 3 dates :

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default comparison between 3 dates :

    I need to return the boolean value based on the below condition. the calculate the date between from date , current date , to date and return the date basd on condition
    fromdate(1st) -------currentdate(2nd)---------todate(3rd)

    fromdate= before date/null
    currentdate= system date
    todate= afterdate/null

    1 fromdate and todate is not null and current date is between fromdate and todate ,then it returns true
    2.fromdate not null and fromdate <= currentdate and todate is null ,then it returns true
    3.fromdate null and currentdate <= todate and todate is not null, it returns true
    4.fromdate =null and todate =null , it returns false

    the code i had written
    ************************************************** ***********************************
    if (fromdate!=null && todate!=null && fromdate.compareTo(currentDate)<0 && todate.compareTo(currentDate)>0)
    {return true;}
    if else(fromdate!=null && fromdate.compareTo(currentDate)<0 && todate=null){return true;}
    if else(todate !=null && todate.compareTo(currentDate)>0 && fromdate=null){return true;}
    ifelse (fromdate==null && todate ==null) {return false;}
    else{return false;}
    ************************************************** **********************************
    It throws the null pointer exception, please help me out .


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: comparison between 3 dates :

    It throws the null pointer exception
    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    BTW What you've posted is NOT valid java code. There is no if else
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Comparison of Objects and such
    By ineedahero in forum Java Theory & Questions
    Replies: 16
    Last Post: October 15th, 2013, 12:54 PM
  2. Comparing Two Dates
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 27th, 2011, 02:09 PM
  3. Testing if dates are real or not.
    By cardsfan33 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 22nd, 2011, 07:46 PM
  4. table comparison
    By awecode in forum JDBC & Databases
    Replies: 2
    Last Post: October 12th, 2010, 09:37 AM
  5. UTC Dates
    By PedroCosta in forum Java Theory & Questions
    Replies: 4
    Last Post: April 1st, 2010, 11:39 AM