This example describes the. NET's datetime function to get the starting and closing times of the previous month. Share to everyone for your reference. The specific analysis is as follows:
A recurring headache in a report is the need to automatically select the last one months of data as the current report output. Online query some. NET C # Examples, found that the implementation of the more complex, in fact, this problem can be very simple to pass. NET's datetime function, because. NET provides us with the current number of days--system.datetime.now.day functions, as well as the adddays and addmonth functions that increase the days and months.
So we can assume that the current time-current days = last month, and current time-1 months-current days + 1 = Last month start time
And then:
last month starting time:
Copy Code code as follows:
Lastmonthbegin = DateTime.Now.AddMonths (-1). AddDays (1-datetime.now.day);
Last month up time:
Copy Code code as follows:
Lastmonthend = DateTime.Now.AddDays (-datetime.now.day)
Done!!
I hope this article will be described to you. NET program design helps.