Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Date

Date

Scheduled Pinned Locked Moved C#
cssquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    simworld
    wrote on last edited by
    #1

    I want to compare between two dates. One date is System Date mm/dd/yyyy format Other one is User i/p Date in SAME FORMAT. I want to check whether the User I/P date is greater/less/euqal than the system date. How can I compare between them

    J D S S 4 Replies Last reply
    0
    • S simworld

      I want to compare between two dates. One date is System Date mm/dd/yyyy format Other one is User i/p Date in SAME FORMAT. I want to check whether the User I/P date is greater/less/euqal than the system date. How can I compare between them

      J Offline
      J Offline
      J 0
      wrote on last edited by
      #2

      I don't know what you mean by:

      simworld wrote:

      Other one is User i/p Date

      Anyway, you can compare dates as following myDate1 > myDate2 or myDate1 <= myDate2, etc

      S 1 Reply Last reply
      0
      • J J 0

        I don't know what you mean by:

        simworld wrote:

        Other one is User i/p Date

        Anyway, you can compare dates as following myDate1 > myDate2 or myDate1 <= myDate2, etc

        S Offline
        S Offline
        simworld
        wrote on last edited by
        #3

        I want to say.. I have a table that contains columns with date value(System date). In a form a Text box (User i/p)that takes only date in a mm/dd/yyyy format if user date will be greater/less/equal than the system date,then certain event will occur. I want the C# code syntax that will compare those date. i think this give u clear view what my question is??

        J P 2 Replies Last reply
        0
        • S simworld

          I want to say.. I have a table that contains columns with date value(System date). In a form a Text box (User i/p)that takes only date in a mm/dd/yyyy format if user date will be greater/less/equal than the system date,then certain event will occur. I want the C# code syntax that will compare those date. i think this give u clear view what my question is??

          J Offline
          J Offline
          J 0
          wrote on last edited by
          #4

          The date comparison examples I gave before would be how you compare dates. I'm guessing what you mean is that you want to make sure that the user enters a valid date and compare that to another date. To do this you can implement code similar to this: DateTime systemDate = DateTime.Today; DateTime userInputDate; // Try to determine if the user entered a valid date. // If it is, userInputDate will have the date value bool bValidDate = DateTime.TryParse(textBox.Text, out userInputDate); if (!bValidDate) {   // Invalid date entered, alert user  MessageBox.Show(textBox.Text + " is not a valid date!"); } else {   //Perform date comparison   if (systemDate < userInputDate)   {   } }

          1 Reply Last reply
          0
          • S simworld

            I want to compare between two dates. One date is System Date mm/dd/yyyy format Other one is User i/p Date in SAME FORMAT. I want to check whether the User I/P date is greater/less/euqal than the system date. How can I compare between them

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            Convert userIPDate to DateTime

            DateTime DateNow = DateTime.Now.Date;
            return DateNow.CompareTo(userIPDate);

            will return -1 if DateNow is less than, 1 if greater than and 0 if equal to.

            1 Reply Last reply
            0
            • S simworld

              I want to compare between two dates. One date is System Date mm/dd/yyyy format Other one is User i/p Date in SAME FORMAT. I want to check whether the User I/P date is greater/less/euqal than the system date. How can I compare between them

              S Offline
              S Offline
              snorkie
              wrote on last edited by
              #6

              The best way I have found is to subtract one DateTime from another, creating a TimeSpan object. Then use the result of the TimeSpan object to do your testing. Hope this helps! DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Now.AddDays(1); //Compare TimeSpan ts = dt1 - dt2; if (ts.TotalMinutes < 50) { //do good stuff here } Hogan

              1 Reply Last reply
              0
              • S simworld

                I want to say.. I have a table that contains columns with date value(System date). In a form a Text box (User i/p)that takes only date in a mm/dd/yyyy format if user date will be greater/less/equal than the system date,then certain event will occur. I want the C# code syntax that will compare those date. i think this give u clear view what my question is??

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                Use a DateTimePicker, not a TextBox.

                1 Reply Last reply
                0
                • S simworld

                  I want to compare between two dates. One date is System Date mm/dd/yyyy format Other one is User i/p Date in SAME FORMAT. I want to check whether the User I/P date is greater/less/euqal than the system date. How can I compare between them

                  S Offline
                  S Offline
                  simworld
                  wrote on last edited by
                  #8

                  thank u very much to all of u ,for helping me.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups