Author Topic: Converting number of days into a MM/DD/YYYY format with name of the day  (Read 836 times)

I'm working converting a number that is a day of a year into a day, month, and year along with a name of the day. I'm thinking of ways to do this and the only way I can come up with is using a ton of if statements to convert a day in between two certain number of days and turning them into a month. Then when getting the day of a month I subtract the number of days in the months before that date. I was wondering if there is a way to do this simpler than I currently am doing it.

If I understood your question correctly, which I probably didn't. You're trying to convert a inputted amount of days, and have it sort itself out?
Code: [Select]
function serverCmdInputDays(%client, %days)
{
      %y = (%days / 30) / 12;
      %m = (%days / 30) % 12;
      %d = %days % 30;

      messageclient(%client,'', %m @ "/" @ %d @ "/" @ %y);
}

Honorable3's method will give an approximation, but it won't be exact because it assumes every month is 30 days.

Honorable3's method will give an approximation, but it won't be exact because it assumes every month is 30 days.
Technically every month is 30.4375 days.
But if you want to actually be able to have an accurate amount; you need a starting day/month/year so that you can calculate the length of each month and go on from there.

Honorable3's method will give an approximation, but it won't be exact because it assumes every month is 30 days.

I know it would be a lot easier to set each month to 30 days even. But I was wondering if there is a way to do it so each month has the correct amount of days, without requiring a ton of if statements.

Create a list of the days of the month, iterate through the list, then subtract the input by the next month's number of days until the input is less than the next month's number of days.