Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I get the date of the friday before the last monday of the month?
For example, say in May, the date of last monday is 28th.
The friday before that is 25th. How is this calculated please?
Thanks
Posted
Comments
Sergey Alexandrovich Kryukov 29-May-12 12:01pm    
What did you try so far? There are no any special secret, you can just think of a simple algorithm to get it.
--SA
Sandeep Mewara 29-May-12 12:19pm    
Did you try?

1 solution

Have a look at this: DateTime extensions for to make some simple tasks a little more readable[^] - it should cover what you want, with a little tweaking.
 
Share this answer
 
Comments
OriginalGriff 29-May-12 12:40pm    
I notice that the tip was missing a method:

/// <summary>
/// Returns the last day in the current month
/// </summary>
/// <example>
/// DateTime endOfMonth = DateTime.Now.LastDayOfMonth();
/// </example>
/// <param name="dt" />Start date
/// <returns></returns>
public static DateTime LastOfMonth(this DateTime dt)
{
int daysInMonth = DateTime.DaysInMonth(dt.Year, dt.Month);
return dt.FirstOfMonth().AddDays(daysInMonth - 1).AtMidnight();
}

Unfortunately, I didn't get the email saying it was missing! I have added it to a new version, which should be approved soon, but here it is anyway.
Maciej Los 29-May-12 12:42pm    
Good article, OriginalGriff ;)
+5!

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