-2

I have the following info:

int year = 2014;
String month_one = "Jun";
String month_two = "Jul";
String day = "Wed";

I want to get the number of weeks between the two dates but the problem is the number of day is not specified and its just the name of the day?

The first date is 2014 Jun Wednesday

The second date is 2014 Jul Wednesday

The day specified will always fall on the first occurrence of the month.

Arnold Cristobal
  • 843
  • 2
  • 16
  • 36
  • 4
    You answered your own question. You don't have enough information to solve the problem, since there are obviously several wednesdays in both months. This shows a design problem elsewhere. – JB Nizet Aug 16 '15 at 08:28
  • so you might get 8 weeks as well as 1 week if day isn't specified. – itwasntme Aug 16 '15 at 08:28
  • The day specified will always fall on the first occurence of the month. – Arnold Cristobal Aug 16 '15 at 08:29
  • A range could be given, minimum x weeks, maximum y weeks. Would that help? – Benjamin Marwell Aug 16 '15 at 08:30
  • *"The day specified will always fall on the first occurence of the month"* Huh?? I'm afraid that sentence doesn't make any sense. A month only occurs once in a year. – T.J. Crowder Aug 16 '15 at 08:30
  • So, what you actually want is to compute the difference in weeks between the first wednesday of a month and the first wednesday of another month, right? If that's correct, now that you've expressed the problem correctly, solving it should be much easier. You need to be able to find the actual date of the first wednesday of a month, and you need to find the difference in weeks between two dates. Use joda-time of the Java 8 time API, and try something. – JB Nizet Aug 16 '15 at 08:32
  • 1
    Maybe try clarifying your question by giving us the signature for a method you're trying to implement, and input/output examples? – Chris Martin Aug 16 '15 at 08:33
  • If you mean the **first Wednesday** of each month, well, that's straight-forward enough: Find the date of the first Wednesday in June 2014, then the date of the first Wednesday in July, and figure the number of weeks between. What's the question? Try to solve the problem and *if* you have a specific problem doing so, post a question about that specific problem. – T.J. Crowder Aug 16 '15 at 08:33
  • This Question is really multiple questions, all of which are duplicates. How to determine a [first Wednesday of the month](http://stackoverflow.com/q/9854379/642706), how to calculate elapsed span of time and extract number of days ([this](http://stackoverflow.com/q/22216132/642706), [this](http://stackoverflow.com/q/7807119/642706), [this](http://stackoverflow.com/q/567659/642706), [this](http://stackoverflow.com/q/22773412/642706), [this](http://stackoverflow.com/q/635935/642706)), and many more. It's good that you want to participate, but please search before posting. – Basil Bourque Aug 16 '15 at 21:39

1 Answers1

-1

Every month has four or five week numbers for a certain day type, i.e. if a month starts with Monday and the month has 31 days, then the month will contain 5 Monday,Tuesday, Wednesday, and 4 from another day types. In order to solve your problem, you should get construct a new Date object with the 1 day of the month to know it's type, then add a number to it to find your day type. After that you can simply calculate from the remaining day number all the days for which are the given type.

gyurix
  • 1,106
  • 9
  • 23