How can I set a DateTime to the first of the month in C#?
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.
The DateTime. AddMonths() method in C# is used to add the specified number of months to the value of this instance.
var now = DateTime.Now; var startOfMonth = new DateTime(now.Year,now.Month,1);
Something like this would work
DateTime firstDay = DateTime.Today.AddDays(1 - DateTime.Today.Day);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With