Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting date and adding to it

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
Disclaimer: First Java program!!

I have a class that I need to find out what today's date is and add a certain number of days to that. I then need to format that date as YYYYMMDD in order to include it in my query...

1. How do I find out what today's date is?
2. How do I format that date as a string in YYYYMMDD?

Thanks!



Leslie

In an open world there's no need for windows and gates
 
well, using my google powers, I found the answer to getting the date, now I just need to figure out how to add 10 days to it before formatting....

Code:
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
    	
    	
    	SearchDate = format.format(new java.util.Date());

Leslie

In an open world there's no need for windows and gates
 
You would probably do best creating a calendar object. Then you can add 1 to the day field.

_________________
Bob Rashkin
 
here's the answer I came up with (with help from co-workers!):
Code:
Calendar cal = Calendar.getInstance();
cal.add(cal.DAY_OF_MONTH, leadTime);
    	
java.util.Date DateValue = cal.getTime();
    	
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        
SearchDate = format.format(DateValue);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top