Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
First day of month
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00727074
Message ID:
00727093
Vues:
13
Another option to calculate the last day of the month is to use the DaysInMonth method like the following:
// Returns number of days in the current month
int NumDays = DateTime.DaysInMonth(DateTime.Now.Year,DateTime.Now.Month);

// Creates a DateTime that is the last day of the current month
new DateTime(DateTime.Now.Year,DateTime.Now.Month,DaysInMonth(DateTime.Now.Year,DateTime.Now.Month));
>>Using C#, how do you get the first day in the current month? Or the last day in the current month?
>>
>>Thanks,
>>
>>Jerry
>
>You can use code like:
>
>
>System.DateTime dateFirstOfMonth = new System.DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, 1, 0, 0, 0);
>System.TimeSpan oneDay = new System.TimeSpan(1, 0, 0, 0, 0);
>System.DateTime dateLastOfMonth = dateFirstOfMonth.Subtract(oneDay);
>
>
>You'll have to adjust it for the first of the current month, but hopefully the code gives you an idea on how. There might be other ways...
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform