c# - How to check date between 2 dates (not SQL) -


In your WinForm, in the text box as' 210514 'or' 231113, let's assume user input (in ddmmyy format) today's date = 291014 (29-Oct-14). Using Visual Studio 2010 C # 4.0 PC Date Time Settings: GMT +08: 00 DD-MMM-Y

CodeBehind:

  // Divide the input string into YYMMDD format and set it to a date Object DateTime InputData = New DataTime (Convert. Keywords: Sebstring (4, 2), convert .to IN 32 (input. Sebstring (2, 2)), convert.OINT 32 (input. Springing (0, 2));   

// WinForm does not allow user input date for more than 1 month before 2 years before today's date and today DateTimeData = Date Time.Now Add Moments (-24); Date time Maximum date = Date time.Now AddMonths (1); I tried several methods but did not do any work (I have also checked several threads / forums).

  // Method 1 if (inputDate> = minDate & amp; amp; amp; input rate & amp; lt; = maxDate) return true / / method 2: B return is true, but A. *** Always *** return false, why ?? If (inputDate> = minDate) A = true; If (InputDate> lt; = maxDate) B = true; // Method 3: B returns true but A *** always *** return false, why ?? If ((datetime) now - inputdate. Day> date = (date time.Number-date date). Days) A = true; If (InputDate> lt; = maxDate) B = true;    

I am posting it as a reply so that I can post the code . I have done this:

  DateTime inputdate; If (Datetime. TryParseExact (this.textbox1.Text, "ddMMyy", blank, datetime style, any, output out)) {var minDate = DateTime.Today.updates (-2); var maxDate = Date Time today. AddMonths (1); Var A = InputDate & gt; = minDate; Var B = InputDate & lt; = MaxDate; MessageBox.Show (string.Format ("Input: {1: d} {0} minutes: {2: d} {0} Max: {3: d} {0} a: {4} {0} b: { 5} ", Environment. New Line, InputDate, Minadet, MaxDate, A, B)); } Other {message box. Show ("invalid input"); }   

I have entered "091014" in my textbox and the message says that A was true . Similarly for "101012" and "101014" unless there is something corrupted on your system, this code is not, but it is to check the exact code of who you are, and see if you get the same result .

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -