"patrick delifer" <pd******@videotron.ca> wrote in message news:%K*********************@wagner.videotron.net. ..

current view of the calendar. The calendar has always 42 cells.

I would like to know if there is a way to know which date is displayed in

the first cell of the calendar.

I'm not certain which Calendar you're using, so this may not be applicable.

On the ASP.NET Calendar (System.Web.UI.WebControls) you can get

the "current month" off of the TodaysDate property. The first row should

contain the first day of that current month ( Month 1, Year ).

Then, the date of the first day of the first week depends on what Day

of the Week that is, i.e., February 1, 2005 was a Tuesday.

Therefore, in a culture where Sunday is the first Day of the Week (which

you can read off of the FirstDayOfWeek property of the afforementioned

ASP.NET Calendar; in particular it will be Monday in some cultures)

then you subtract one day (Monday = 0, Tuesday = 1, ...) from the

number of days in the month preceding the "current month" (31 days

hath January...).

Answer: Sunday, January 30, 2005.

In summary -- find out what Month you're in, go to the first Day in that

Month, calculate the Day Of the Week, and then subtract to reach the

Date of the First Day Of Week (the amount you subtract is determined

by what Day Of the Week the first Day in the Month is, and the number

you subtract from is determined by the number of Days in the preceding

Month).

If you Calendar control doesn't keep the first day of the month on the

first row (if it just scrolls through six weeks at a time) then this algorithm

won't work all the time because sometimes you'll encounter the whole

first week as being days from the previous Month.

Derek Harmon