Return a date string given the day number/count

I am looking for a way to get the Month number and Day number given the number of days into a given year. I have a date code that I can capture that is 4 digits. The first digit is the year number, in the case of this year, it is 8. The next 3 digits are for the day of the year, for example 8030 would be January 30th, 2008 or 01/30/08. I figure there is some built in function that will allow me to decode 291 into whatever the 291st day of the year is, allowing for leap years.

Thanks in advance.

What happens in 2010?

In 2010, it rolls back to 0 again.

Picture me shuddering in horror. When does this processing occur? Can we just assume its always the current year when the code we need to write executes, and translates your 4-digit code into something useful?

Ok, the java.util.Calendar class is going to help you with your number of days problem. For example, this code would give you a number of days offset into the current year:

from java.util import Calendar cal = Calendar.getInstance() # will return with the current date set cal.set(Calendar.DAY_OF_YEAR, 291) month = cal.get(Calendar.MONTH) # this will be an integer (January=0, FYI) day = cal.get(Calendar.DAY_OF_MONTH) # this will be an integer date = cal.getTime() # this will be a Date object that you can use

I’m not quite sure in what context you’re using this - how do you get this 4-digit date, and what do you want to do with it once converted?

Thanks for the code and I know what you mean. The good part is that this code is some portion of the information that our customers find on our bottles. It is sort of a Julian date. I am going to use this information to limit the listing of packagings that are pulled up in a dropdown box. Since I will sort the information in the dropdown box in decending order by date, the information they will be looking for will probably be in the top dozen or so lines of the dropdown listing. If they are looking for one from last year or the year before, they will just be further down the list. Kind of a comprimise between me wanting them to select the correct packaging code from a list and allowing them to enter it free text.