Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I convert month and day to the day of the year?

For example, converting FEBRUARY 1 to 32, with 32 meaning the 32nd day of the year.

There is a struct that needs to be a part of it. The struct could be something like this:

struct person {
  char name[30]
  char month;
  int day;
}
Posted
Updated 25-Mar-10 8:43am
v3

for January, day of year equals day of month;
for February, day of year equals day of month plus 31;
for all other months, you can't say without knowing the leap year situation.

:)
 
Share this answer
 
Take a look at the Time Management[^] functions in C. The struct tm type has a property containing the day of the year, so you just need to use the other functions to convert from a string to a date.
 
Share this answer
 
What you're talking about is converting a Gregorian date to a Julian date.

See: Converting Between Julian Dates and Gregorian Calendar Dates [^]. You can write the equation in C, and then if you want the day of the year, just subtract the julian date of the day in question from the julian date from the 1st of January of the year.
 
Share this answer
 
Try out this link (nice explanation and formulae):
http://www.codecogs.com/d-ox/units/date/dayofyear.php[^]
 
Share this answer
 
Check this, you can use the logic.

http://www.dotnetspider.com/resources/21013-C-function-will-determine-day-number-within.aspx[^]


added, LP:

That link points to C# code and relies on the DateTime class in .NET, that is not very relevant to the question which specified C. The code also is horrible as it converts a DateTime to a string, later on parses it again to a DateTime, etc.

X|
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900