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. Web Development
  3. ASP.NET
  4. date difference

date difference

Scheduled Pinned Locked Moved ASP.NET
questionhelp
10 Posts 4 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.
  • R Offline
    R Offline
    R Thomas 0
    wrote on last edited by
    #1

    hi.... lets say i have a date an old date... how can i get the difference in date(not the hour and sec and min.) only the date difference between that 2 year old date and currect date?? and get the answer as date? can someone pls help?? tks... "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

    R N 2 Replies Last reply
    0
    • R R Thomas 0

      hi.... lets say i have a date an old date... how can i get the difference in date(not the hour and sec and min.) only the date difference between that 2 year old date and currect date?? and get the answer as date? can someone pls help?? tks... "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

      R Offline
      R Offline
      RickardB
      wrote on last edited by
      #2

      I am not sure that I have understood your question correctly, but here is an example how you could get the timedifference between to dates: //Lets say we want the time difference from 2002-02-25 to today. DateTime t2 = DateTime.Now; DateTime t1 = System.Convert.ToDateTime("2002-02-25"); int years = t2.Year - t1.Year; int months = t2.Month - t1.Month; int days = t2.Days = t1.Day; Rickard - Keep Reflecting

      R N 2 Replies Last reply
      0
      • R R Thomas 0

        hi.... lets say i have a date an old date... how can i get the difference in date(not the hour and sec and min.) only the date difference between that 2 year old date and currect date?? and get the answer as date? can someone pls help?? tks... "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        TimeSpan diff = DateTime.Now - oldtime; int nDays = diff.Days You're never going to get anywhere if you can find the answer to such simple questions yourself.

        R 1 Reply Last reply
        0
        • R RickardB

          I am not sure that I have understood your question correctly, but here is an example how you could get the timedifference between to dates: //Lets say we want the time difference from 2002-02-25 to today. DateTime t2 = DateTime.Now; DateTime t1 = System.Convert.ToDateTime("2002-02-25"); int years = t2.Year - t1.Year; int months = t2.Month - t1.Month; int days = t2.Days = t1.Day; Rickard - Keep Reflecting

          R Offline
          R Offline
          R Thomas 0
          wrote on last edited by
          #4

          i was looking for an asnwer that does the calculation for me instead of making me do the subtraction of days and months and years one by one... its quite tedious if i do it that way... i managed to figure out a solution anyway... tks for your effort:) "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

          A 1 Reply Last reply
          0
          • R RickardB

            I am not sure that I have understood your question correctly, but here is an example how you could get the timedifference between to dates: //Lets say we want the time difference from 2002-02-25 to today. DateTime t2 = DateTime.Now; DateTime t1 = System.Convert.ToDateTime("2002-02-25"); int years = t2.Year - t1.Year; int months = t2.Month - t1.Month; int days = t2.Days = t1.Day; Rickard - Keep Reflecting

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #5

            This would give 0 for the days. My reply below would give the correct difference between these dates as 761 days.

            A 1 Reply Last reply
            0
            • N Not Active

              TimeSpan diff = DateTime.Now - oldtime; int nDays = diff.Days You're never going to get anywhere if you can find the answer to such simple questions yourself.

              R Offline
              R Offline
              R Thomas 0
              wrote on last edited by
              #6

              Mark Nischalke wrote: You're never going to get anywhere if you can find the answer to such simple questions yourself. HEY MARKY!!:mad: did u read my post above??? did YA??!!!!:mad: i found the answer myself... and thru msdn and testing myself FYI!! no internet, no forum!!ok??!!! READ BEFORE U POST!! dtNow = Date.Today tsStatus = dtNow.Subtract(dtUsed) If tsStatus.Days > (365 * 4) Then status = "Inactive" Else status = "Active" End If the answer I CAME UP with may not be as efficent as yours or as HI-FI as yours, but i am a beginner.. Mark Nischalke Status Gold. Member No. 16070 Messages Posted (while logged in) 1,177 Articles Submitted 6 Biography I was born, I lived, then went to Hell Location United States Occupation Software development, Software Consulting, Software Components, Web design, Systems engineering, Other, Not applicable so i am VERY VERY HAPPY!!Cause i CAME UP with it.. FYI- Been doin asp.net for 3 weeks, JS for 2 days, VB.NET for 3 weeks!:suss: "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

              A 1 Reply Last reply
              0
              • N Not Active

                This would give 0 for the days. My reply below would give the correct difference between these dates as 761 days.

                A Offline
                A Offline
                Anonymous
                wrote on last edited by
                #7

                The first thing I was thinking about was your solution but with this solution is rather tricky to get the difference in years, days and months. To get the number of years in difference you have to devide the days with years and then also taking leap years and similar things in consideration.

                1 Reply Last reply
                0
                • R R Thomas 0

                  i was looking for an asnwer that does the calculation for me instead of making me do the subtraction of days and months and years one by one... its quite tedious if i do it that way... i managed to figure out a solution anyway... tks for your effort:) "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

                  A Offline
                  A Offline
                  Anonymous
                  wrote on last edited by
                  #8

                  What is the solution you found? When I wrote my answer I assumed that you already knew about the TimeSpan solution, so I guessed you wanted to do something else.

                  1 Reply Last reply
                  0
                  • R R Thomas 0

                    Mark Nischalke wrote: You're never going to get anywhere if you can find the answer to such simple questions yourself. HEY MARKY!!:mad: did u read my post above??? did YA??!!!!:mad: i found the answer myself... and thru msdn and testing myself FYI!! no internet, no forum!!ok??!!! READ BEFORE U POST!! dtNow = Date.Today tsStatus = dtNow.Subtract(dtUsed) If tsStatus.Days > (365 * 4) Then status = "Inactive" Else status = "Active" End If the answer I CAME UP with may not be as efficent as yours or as HI-FI as yours, but i am a beginner.. Mark Nischalke Status Gold. Member No. 16070 Messages Posted (while logged in) 1,177 Articles Submitted 6 Biography I was born, I lived, then went to Hell Location United States Occupation Software development, Software Consulting, Software Components, Web design, Systems engineering, Other, Not applicable so i am VERY VERY HAPPY!!Cause i CAME UP with it.. FYI- Been doin asp.net for 3 weeks, JS for 2 days, VB.NET for 3 weeks!:suss: "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

                    A Offline
                    A Offline
                    Anonymous
                    wrote on last edited by
                    #9

                    This solution is not correct. Don't forget the leap years. Some years are longer then 365 days.

                    R 1 Reply Last reply
                    0
                    • A Anonymous

                      This solution is not correct. Don't forget the leap years. Some years are longer then 365 days.

                      R Offline
                      R Offline
                      R Thomas 0
                      wrote on last edited by
                      #10

                      i dont need precision... i just need a ROUGH ROUGH APPROX. 4 years.. thats what i need...thats what i wrote the code to find..:cool: "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

                      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