. NET DateTime function to obtain the start and end time of the last month,. netdatetime
This example describes how to obtain the start time and end time of the last month for the. NET DateTime function. Share it with you for your reference. The specific analysis is as follows:
A headache frequently encountered in reports is that the data of the past month must be automatically selected as the output of the current report. I found some information online. net c # examples, found that the implementation is more complex, in fact, this problem can be very simple through. NET DateTime function, because. NET provides the current number of days -- System. dateTime. now. the Day function also includes the AddDays and AddMonth functions for adding days and months.
So we can imagine that the current time-current days = last month's end time, and the current time-1 month-current days + 1 = last month's Start Time
Then:
Last month start time: Copy codeThe Code is as follows: lastMonthBegin = DateTime. Now. AddMonths (-1). AddDays (1-datetime.no1_day );
Last month deadline: Copy codeThe Code is as follows: lastMonthEnd = DateTime. Now. AddDays (-DateTime. Now. Day)
Success !!
I hope this article will help you with the. NET program design.