Does anyone have the script that returns that second last sunday of a month?

T

TaeHo Yoo

I have a scheduling function and in that function I want to excute
something if today is the second last sunday of a month.

Cheers
 
J

Jeff Louie

Well, you can convert this C++ code to get the first Sunday of the month
and then work out the math for a specific Sunday of the month given the
days in the month. Full C++ code at:

http://www.geocities.com/jeff_louie/date.htm

// Days since Sunday 0-6
// Based on Zeller
// ASSERT Year>1, Month>=1 && <=12.
int CCalendar::GetFirstDayInMonth(unsigned int Year, unsigned int
Month)
{
    const int day=1;
    if (Month < 3) {
        Month +=12;
        Year -= 1;
    }
    return ((day+1+(Month*2)+(int)((Month+1)*3/5)+Year+(int)(Year/4)-
(int)(Year/100)+(int)(Year/400))%7);
}

Regards,
Jeff
I have a scheduling function and in that function I want to excute
something if today is the second last sunday of a month.<
 
D

David

I have a scheduling function and in that function I want to excute
something if today is the second last sunday of a month.

Off the top of my head, the easiest thing here would be to check
if the next sunday is still in the same month, but two weeks from
the date in question is not...

private bool CheckSecondLastSunday()
{

DateTime dt = DateTime.Now;

if( (dt.DayOfWeek == DayOfWeek.Sunday) &&
(dt.AddDays(7).Month == dt.Month) &&
(dt.AddDays(14).Month != dt.Month) )

return true;
else
return false;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top