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. Visual Basic
  4. How to find out how many days?

How to find out how many days?

Scheduled Pinned Locked Moved Visual Basic
questiontutorial
8 Posts 3 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.
  • I Offline
    I Offline
    ibok23
    wrote on last edited by
    #1

    I am having to write a code to figure out how many days are from the starting of a project and the ending of the project. I am using the date picker and I have the day of the week, Month, day and year on both the starting and ending. How do I write a code to figure out how many days are in between? Thank you, ibok23

    G 1 Reply Last reply
    0
    • I ibok23

      I am having to write a code to figure out how many days are from the starting of a project and the ending of the project. I am using the date picker and I have the day of the week, Month, day and year on both the starting and ending. How do I write a code to figure out how many days are in between? Thank you, ibok23

      G Offline
      G Offline
      greg lynch _nj_
      wrote on last edited by
      #2

      VB.NET Example Dim FirstDate As Date Dim SecondDate As Date Dim days As Integer Dim hours As Integer Dim minutes As Integer 'Your DatePicker control would capture these dates FirstDate = Now() 'I add 3 days just for example sake SecondDate = DateAdd(DateInterval.Day, 3, FirstDate) 'Use datediff to calculate in days, then hours, then minutes days = DateDiff(DateInterval.Day, FirstDate, SecondDate) hours = DateDiff(DateInterval.Hour, FirstDate, SecondDate) minutes = DateDiff(DateInterval.Minute, FirstDate, SecondDate) Hope this helps Gregory J Lynch Hack

      I 1 Reply Last reply
      0
      • G greg lynch _nj_

        VB.NET Example Dim FirstDate As Date Dim SecondDate As Date Dim days As Integer Dim hours As Integer Dim minutes As Integer 'Your DatePicker control would capture these dates FirstDate = Now() 'I add 3 days just for example sake SecondDate = DateAdd(DateInterval.Day, 3, FirstDate) 'Use datediff to calculate in days, then hours, then minutes days = DateDiff(DateInterval.Day, FirstDate, SecondDate) hours = DateDiff(DateInterval.Hour, FirstDate, SecondDate) minutes = DateDiff(DateInterval.Minute, FirstDate, SecondDate) Hope this helps Gregory J Lynch Hack

        I Offline
        I Offline
        ibok23
        wrote on last edited by
        #3

        This does help. If I only want to find out about how many days do I still need to do the minute and hour (Dim)? Dim hours As Integer Dim minutes As Integer hours = DateDiff(DateInterval.Hour, FirstDate, SecondDate) minutes = DateDiff(DateInterval.Minute, FirstDate, SecondDate) Do I type in this part at the bottom or does the date picker automatically do it? 'Your DatePicker control would capture these dates FirstDate = Now() 'I add 3 days just for example sake SecondDate = DateAdd(DateInterval.Day, 3, FirstDate) Thank you, ibok23

        D 1 Reply Last reply
        0
        • I ibok23

          This does help. If I only want to find out about how many days do I still need to do the minute and hour (Dim)? Dim hours As Integer Dim minutes As Integer hours = DateDiff(DateInterval.Hour, FirstDate, SecondDate) minutes = DateDiff(DateInterval.Minute, FirstDate, SecondDate) Do I type in this part at the bottom or does the date picker automatically do it? 'Your DatePicker control would capture these dates FirstDate = Now() 'I add 3 days just for example sake SecondDate = DateAdd(DateInterval.Day, 3, FirstDate) Thank you, ibok23

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          ibok23 wrote: This does help. If I only want to find out about how many days do I still need to do the minute and hour (Dim)? Dim hours As Integer Dim minutes As Integer No. If you don't need 'em, don't put 'em in. ibok23 wrote: Do I type in this part at the bottom or does the date picker automatically do it? 'Your DatePicker control would capture these dates FirstDate = Now() 'I add 3 days just for example sake SecondDate = DateAdd(DateInterval.Day, 3, FirstDate) You have to supply the code that gets the dates from the date picker's and puts them in variables to use in this calculation. RageInTheMachine9532

          I 1 Reply Last reply
          0
          • D Dave Kreskowiak

            ibok23 wrote: This does help. If I only want to find out about how many days do I still need to do the minute and hour (Dim)? Dim hours As Integer Dim minutes As Integer No. If you don't need 'em, don't put 'em in. ibok23 wrote: Do I type in this part at the bottom or does the date picker automatically do it? 'Your DatePicker control would capture these dates FirstDate = Now() 'I add 3 days just for example sake SecondDate = DateAdd(DateInterval.Day, 3, FirstDate) You have to supply the code that gets the dates from the date picker's and puts them in variables to use in this calculation. RageInTheMachine9532

            I Offline
            I Offline
            ibok23
            wrote on last edited by
            #5

            This is what I wrote, it still doesn't work but maybe I am close. numberofdays.text = datediff(dateinterval.day, dtparrival, dtpcheckout) dtparrival is my date picker for arrival dtpcheckout is my date picker for checkout numberofdays.text shows how many days they are there. What am i doing wrong? Thank you, ibok23

            D 1 Reply Last reply
            0
            • I ibok23

              This is what I wrote, it still doesn't work but maybe I am close. numberofdays.text = datediff(dateinterval.day, dtparrival, dtpcheckout) dtparrival is my date picker for arrival dtpcheckout is my date picker for checkout numberofdays.text shows how many days they are there. What am i doing wrong? Thank you, ibok23

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              ibok23 wrote: numberofdays.text = datediff(dateinterval.day, dtparrival, dtpcheckout) You're about half way there. The last two parameters you passed in are the references for the DateTimePicker controls themselves, not their values. Make the following change to get at the Value's in your controls:

              numberofdays.Text = DateDiff(DateInterval.Day, dtparrival.Value, dtpcheckout.Value)

              RageInTheMachine9532

              I 1 Reply Last reply
              0
              • D Dave Kreskowiak

                ibok23 wrote: numberofdays.text = datediff(dateinterval.day, dtparrival, dtpcheckout) You're about half way there. The last two parameters you passed in are the references for the DateTimePicker controls themselves, not their values. Make the following change to get at the Value's in your controls:

                numberofdays.Text = DateDiff(DateInterval.Day, dtparrival.Value, dtpcheckout.Value)

                RageInTheMachine9532

                I Offline
                I Offline
                ibok23
                wrote on last edited by
                #7

                ooookkkk, I see. I am still working on the currency part and then I'll debug it to see if it works. Hopefully. One more question if you don't mind. numberofdays.text = (will be a number, correct) ok what if I need to charge somebody $5.00 for every number of days I wrote this and it didn't work dim rollawaybed as double = 5 rollawaybedcharge.text = (rollawaybed * numberofdays.text) then I have to put about the currency, but I am getting that this will not work. :) Thank you, ibok23

                D 1 Reply Last reply
                0
                • I ibok23

                  ooookkkk, I see. I am still working on the currency part and then I'll debug it to see if it works. Hopefully. One more question if you don't mind. numberofdays.text = (will be a number, correct) ok what if I need to charge somebody $5.00 for every number of days I wrote this and it didn't work dim rollawaybed as double = 5 rollawaybedcharge.text = (rollawaybed * numberofdays.text) then I have to put about the currency, but I am getting that this will not work. :) Thank you, ibok23

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  ibok23 wrote: dim rollawaybed as double = 5 rollawaybedcharge.text = (rollawaybed * numberofdays.text) Well, you're trying to multiply a Double (number) by a String (.Text). You can't do that. But what you can do is convert the String TO a number first:

                  Dim rollawaybed As Double = 5
                  Dim newcharge As Double = rollawaybed * Val(numberofdays.Text)
                  rollawaybedcharge.Text = Format(newcharge, "C")

                  Val will convert a string of numbers, like 5 or 5000 (NO PUNCTUATION!), into a actual value that can be used in calculations. RageInTheMachine9532

                  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