Bill
Thu Jun 21 10:03:46 CDT 2007
Not relevant :-) but it is such a lovely algorithm (sort of):
static int dayofweek( int year, int month, int day)
{
#if 0
Zeller's Congruence
Where: weekday = (0=Sun, 1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat)
day = day of the month
month = month of year (Jan & Feb = 13 & 14 of prev year)
year = year (year - 1 if month is Jan or Feb)
INT = integer part (eg: INT(3.5) = 3)
MOD = modulus or remainder part (eg: (10 MOD 7) = 3)
Example: Feb 12, 1809 day = 12, month = 14, year = 1808 (weekday = 0 Sun)
Jul 4, 1776 day = 4, month = 7, year = 1776 (weekday = 4 Thu)
#endif
if ( month==1 || month==2 )
month += 12, year -= 1;
return ( ( day + 1
+ ( month * 2 )
+ (int)( ( month + 1 ) * 3 / 5 )
+ year
+ (int)( year / 4 )
- (int)( year / 100 )
+ ( year / 400 ) ) % 7 );
}
"Tom Serface" <tom.nospam@camaswood.com> wrote in message
news:%237bOHPBtHHA.1168@TK2MSFTNGP02.phx.gbl...
>I don't know of a "built in" way to do this sort of calculation. As you
>say, it would be easy enough to figure it out in a small function. You
>could figure out the month by creating a cumulative array of month/days and
>the day would be whatever is left over. You'd have to account for leap
>year so that would mean you'd need to know the current year. That is
>pretty easy to get :o)
>
>
http://www.codeproject.com/cpp/LeapYear.asp
>
> Tom
>
> "Z.K." <nospam@nospam.net> wrote in message
> news:eghRpHBtHHA.1168@TK2MSFTNGP02.phx.gbl...
>>I have a variable time in the number of days such as 1 to 366 and I was
>>wondering if there is a simple function that will convert it to the month
>>and day of the month. I can do it myself, but I was just wondering if
>>there is an easy builtin function that I could use. I am using Visual
>>C++. Normally, I use strftime as it is very useful and has many options,
>>but I did not see a way to convert the days of the year to month and day.
>>
>> Z.K.
>>
>