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

  • Home
  • SEARCH
  • 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 7794705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:51:08+00:00 2026-06-01T22:51:08+00:00

How can we add or subtract date in java? For instance java.sql.Date and formatted

  • 0

How can we add or subtract date in java? For instance java.sql.Date and formatted like this: yyyy-MM-dd, how can i Add 5 months from that? I’ve seen in some tutorial that they are using Calendar, can we set date on it? Please Help.

Example: 2012-01-01 when added 5 months will become 2012-06-01.

PS: I’m a .Net Programmer and slowly learning to Java environment.

  • 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-01T22:51:09+00:00Added an answer on June 1, 2026 at 10:51 pm

    First of all you have to convert your String date to java.util.Date, than you have to use java.util.Calendar to manipulate dates. It is also possible to do math with millis, but I do not recommend this.

    public static void main( final String[] args ) throws ParseException {
        final String sdate = "2012-01-01";
        final SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd" );
        final Date date = df.parse( sdate ); // conversion from String
        final java.util.Calendar cal = GregorianCalendar.getInstance();
        cal.setTime( date );
        cal.add( GregorianCalendar.MONTH, 5 ); // date manipulation
        System.out.println( "result: " + df.format( cal.getTime() ) ); // conversion to String
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use EXSLT extensions to subtract a date. I see that there
You can add and subtract 1 from my cell.textLabel.text . I am adding 1
I can add a Conditional statement to a breakpoint, for instance arg0.startsWith(something) but i'd
I know that I can add a HintPath to an external DLLs to help
How i can add the multiple values from a datagrid to textbox in C#?
I want to manage a Google Reader folder of feeds that I can add
I have a string that looks like (3) New stuff where 3 can be
This seems like something that should be easy, but I am having a tough
How can I add, subtract, and compare binary numbers in Python without converting them
Ok i have a table view that can add and delete cells. For each

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.