C # Gets the last day of the month 23:59:59 and the first day of the month 00:00:00

Source: Internet
Author: User

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" &GT;&LT;/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" &GT;&LT;/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&gt        ; public datetime Firstdayofupmouth (datetime datetime) {return datetime. AddDays (1-datetime. Day).        AddMonths (-1); }///<summary>//Get last day of last month///</summary>//<param name= "datetime" >&lt             ;/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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.