Project requirements:
A school order deadline for the last one months of the final day of the year before 23:59:59 all the paid order statistics;
Code:
<summary>///through school and deadlines///</summary>/<param name= "PageIndex" > Number of pages </param>//<param name= "pageSize" > Page area </param>//<param name= "SchoolID" > School ID&L t;/param>//<param name= "Ordersettlementendtime" > Cut-off time </param>//<returns></retur Ns> public pagedlist<order> getorderbyschoolandendtime (int pageindex,int pagesize,guid? schoolId, DateTime ? Ordersettlementendtime) {var query = this. Table; if (schoolid.hasvalue) {query = query. Where (x = X.schoolid = = SchoolID); } if (Ordersettlementendtime.hasvalue) {//Last day of the month var endmonth = Date Time.parse (OrderSettlementEndTime.Value.AddDays (1-ordersettlementendtime.value.day) . AddMonths (1). AddDays (-1) . ToString ()); Last last day var startmonth = DateTime.Parse (ordersettlementendtime . Value.adddays (1-ordersettlementendtime.value.day). AddSeconds (-1). ToString ()); query = query. Where (x = x.createtime >= startmonth&&x.createtime<endmonth); } return query. Where (x = x.paymentstate = = paymentstate. Payment completed). (x=>x.id). Topagedlist (pageindex,pagesize); }Image:
Using DateTime.Parse (); Converting a string of time to a datetime type, let's look at the following code, which sets the time manually to the time we need.
DateTime today12hours = DateTime.Parse (DateTime.Now.ToString ("Yyyy-mm-dd 12:00:00"));
So we set the value.
How to encapsulate the time taken
<summary>///Last day of the month///</summary>//<param name= "datetime" ></PA ram>//<returns></returns> public datetime firstdayofmonth (datetime datetime) { return datetime. AddDays (1-datetime. Day). AddMonths (1). AddDays (-1); }///<summary> last day of January////</summary>//<param name= "datetime" ></ param>//<returns></returns> public datetime lastdayofmonth (datetime datetime) { return datetime. AddDays (1-datetime. Day). AddSeconds (-1); }///<summary>///First day of the month///</summary>//<param name= "datetime" ></PA ram>//<returns></returns> public datetime firstdayofmonthmethod (datetime datetime) {return DateTime. AddDays (1-datetime. Day); }///<summary>//On the first day of January </summary>//<param name= "datetime" ></param>//<returns></returns> ; public datetime Firstdayofupmouth (datetime datetime) {return datetime. AddDays (1-datetime. Day). AddMonths (-1); }///<summary>//Get last day of last month///</summary>//<param name= "datetime" >< ;/param>//<returns></returns> public datetime lastdayofonmouth (datetime datetime) { return datetime. AddDays (1-datetime. Day). AddDays (-1); }
C # Gets the last day of the month 23:59:59 and the first day of the month 00:00:00