Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set DateTime to start of month

Tags:

c#

How can I set a DateTime to the first of the month in C#?

like image 266
learning Avatar asked Feb 15 '11 10:02

learning


People also ask

How do I find the first and last date of the month?

To get the first and last day of the current month, use the getFullYear() and getMonth() methods to get the current year and month and pass them to the Date() constructor to get an object representing the two dates.

How can I add 1 month to date in asp net?

The DateTime. AddMonths() method in C# is used to add the specified number of months to the value of this instance.


2 Answers

var now = DateTime.Now; var startOfMonth = new DateTime(now.Year,now.Month,1); 
like image 197
Nick Jones Avatar answered Sep 24 '22 11:09

Nick Jones


Something like this would work

DateTime firstDay = DateTime.Today.AddDays(1 - DateTime.Today.Day); 
like image 23
V4Vendetta Avatar answered Sep 25 '22 11:09

V4Vendetta