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