Tag: Sum time returns ring INF ret via COM IMA
Methods for comparing two date sizes in C #
/// <summary> ///comparison of two date sizes/// </summary> /// <param name= "DATESTR1" >Date 1</param> /// <param name= "DATESTR2" >Date 2</param> /// <param name= "MSG" >return information</param> Public voidCompanydate (stringDATESTR1,stringDATESTR2,ref stringmsg) { //Convert a date string to a Date objectDateTime T1 =Convert.todatetime (DATESTR1); DateTime T2=Convert.todatetime (DATESTR2); //Compare by Datetime.compare ( ) () intCompnum =datetime.compare (t1, T2); //t1> T2 if(Compnum >0) {msg="T1: ("+ DATESTR1 +") is greater than"+"T2 ("+ DATESTR2 +")"; } //t1= T2 if(Compnum = =0) {msg="T1: ("+ DATESTR1 +") equals"+"T2 ("+ DATESTR2 +")"; } //t1< T2 if(Compnum <0) {msg="T1: ("+ DATESTR1 +") is less than"+"T2 ("+ DATESTR2 +")"; } }
Code to invoke
PublicActionResult Index () {//t1< T2 stringMSG1 =string. Empty; stringDate1 ="2018-07-25"; stringDate2 ="2018-07-27"; Companydate (Date1,date2,refMSG1); //t1> T2 stringMSG2 =string. Empty; stringDate3 ="2018-07-27"; stringDate4 ="2018-07-25"; Companydate (Date3, Date4,refMSG2); returnView (); }
Overall demo Source
Public classTestcontroller:controller {//get:test PublicActionResult Index () {//t1< T2 stringMSG1 =string. Empty; stringDate1 ="2018-07-25"; stringDate2 ="2018-07-27"; Companydate (Date1,date2,refMSG1); //t1> T2 stringMSG2 =string. Empty; stringDate3 ="2018-07-27"; stringDate4 ="2018-07-25"; Companydate (Date3, Date4,refMSG2); returnView (); } /// <summary> ///comparison of two date sizes/// </summary> /// <param name= "DATESTR1" >Date 1</param> /// <param name= "DATESTR2" >Date 2</param> /// <param name= "MSG" >return information</param> Public voidCompanydate (stringDATESTR1,stringDATESTR2,ref stringmsg) { //Convert a date string to a Date objectDateTime T1 =Convert.todatetime (DATESTR1); DateTime T2=Convert.todatetime (DATESTR2); //Compare by Datetime.compare ( ) () intCompnum =datetime.compare (t1, T2); //t1> T2 if(Compnum >0) {msg="T1: ("+ DATESTR1 +") is greater than"+"T2 ("+ DATESTR2 +")"; } //t1= T2 if(Compnum = =0) {msg="T1: ("+ DATESTR1 +") equals"+"T2 ("+ DATESTR2 +")"; } //t1< T2 if(Compnum <0) {msg="T1: ("+ DATESTR1 +") is less than"+"T2 ("+ DATESTR2 +")"; } } }
Specific:
1) Figure 1
2) Figure 2
How do you compare the size of two dates in C # code?