how to Caluclate This Week and Last week start and End Dates ?

I have four radio buttons for Today | This Week | Last Week  | Date

i can easily figure out Date and Today.

I need help with "This Week" And "Last week "

Could you please tell me how should i cacluate start and end dates of "This Week" and "last week"  in Java

i know i ahve to use calender. I need code please :(
SiddhardhAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kevin CrossChief Technology OfficerCommented:
Here is a rough example of how you would do this...
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_WEEK, 1-cal.get(Calendar.DAY_OF_WEEK));
Date startOfWeek = cal.getTime();
 
cal.add(Calendar.DAY_OF_WEEK, 6);
Date endOfWeek = cal.getTime();
 
cal.add(Calendar.DAY_OF_WEEK, -7);
Date endOfLastWeek = cal.getTime();
 
cal.add(Calendar.DAY_OF_WEEK, -6);
Date startOfLastWeek = cal.getTime();
		
System.out.println("Start of this week is: " + startOfWeek.toString());
System.out.println("End of this week is: " + endOfWeek.toString());
System.out.println("Start of last week is: " + startOfLastWeek.toString());
System.out.println("End of last week is: " + endOfLastWeek.toString());		

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SiddhardhAuthor Commented:
Thanks a lot !
0
SiddhardhAuthor Commented:
I closed it without verifying sorry.The solution you gave takes Sunday as Start Date and Saturday as End Date. I want Monday as Start Day in the Week and Sunday as End Day in the week. I need their dates.
0
SiddhardhAuthor Commented:
I did this got it

cal.add(Calendar.DAY_OF_WEEK, 2-cal.get(Calendar.DAY_OF_WEEK));
            Date startOfWeek = cal.getTime();
             
            cal.add(Calendar.DAY_OF_WEEK, 6);
            Date endOfWeek = cal.getTime();
             
            cal.add(Calendar.DAY_OF_WEEK, -7);
            Date endOfLastWeek = cal.getTime();
             
            cal.add(Calendar.DAY_OF_WEEK, -6);
            Date startOfLastWeek = cal.getTime();
0
Kevin CrossChief Technology OfficerCommented:
That works, glad you got it.


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.