Hi guys, I am currently doing a Car rental website project. Like my Car collection and return date is like in the website. http://www.avis.com/...visHome/home.ac
Well i need a function or method to calculate the number of days between Collection date/time and return date/time.
Please assist.
Time spent in reading my problem is deeply appreciated. Hope that anyone who know can help.
Thanks~
-Kelvin
3 Replies - 10500 Views - Last Post: 15 February 2009 - 02:00 PM
#1
How to calculate number of days between 2 Dates/time
Posted 11 February 2009 - 04:15 AM
Replies To: How to calculate number of days between 2 Dates/time
#2
Re: How to calculate number of days between 2 Dates/time
Posted 11 February 2009 - 12:56 PM
Use the library function "DateAdd"
Simple.
Say Thanks!
For more date functions, check my tutorial out!
http://www.dreaminco...wtopic83102.htm
Private Sub Datecalc_Click()
Dim Date1 as Date
Dim Date2 as Date
Date1=Inputbox("Enter date1")
Date2=Inputbox("Enter date2")
Print DateDiff("d",Date1,Date2)
'Here "d" is used to set interval to days
End Sub
Simple.
Say Thanks!
For more date functions, check my tutorial out!
http://www.dreaminco...wtopic83102.htm
#3
Re: How to calculate number of days between 2 Dates/time
Posted 15 February 2009 - 01:58 AM
Hi, I tried :
Dim startdate As DateTime
Dim enddate As DateTime
'Section 1
startdate = MonthList1.SelectedItem.Text & "/" & DayList1.SelectedItem.Text & "/" & YearList1.SelectedItem.Text & " " & HourList1.SelectedItem.Text & ":" & MinuteList1.SelectedItem.Text
enddate = MonthList2.SelectedItem.Text & "/" & Daylist2.SelectedItem.Text & "/" & YearList2.SelectedItem.Text & " " & HourList2.SelectedItem.Text & ":" & MinuteList2.SelectedItem.Text
'Section 2
DateDiff(DateInterval.DayOfYear, startdate, enddate)
But i cant get the answer.
and also..
'
I also tried to over write section 2 for trial and error purposes.
'Section 2
Dim d as integer
DateDiff("d",Date1,Date2)
d= label.text
But failed.
I also tried
DateDiff(DateInterval.Day, startdate, enddate)
Fail again.
Dayinterval.Day and Dayinterval.Dayofyear has a value of 3 and 4 respectively. How come?
Dim startdate As DateTime
Dim enddate As DateTime
'Section 1
startdate = MonthList1.SelectedItem.Text & "/" & DayList1.SelectedItem.Text & "/" & YearList1.SelectedItem.Text & " " & HourList1.SelectedItem.Text & ":" & MinuteList1.SelectedItem.Text
enddate = MonthList2.SelectedItem.Text & "/" & Daylist2.SelectedItem.Text & "/" & YearList2.SelectedItem.Text & " " & HourList2.SelectedItem.Text & ":" & MinuteList2.SelectedItem.Text
'Section 2
DateDiff(DateInterval.DayOfYear, startdate, enddate)
But i cant get the answer.
and also..
'
I also tried to over write section 2 for trial and error purposes.
'Section 2
Dim d as integer
DateDiff("d",Date1,Date2)
d= label.text
But failed.
I also tried
DateDiff(DateInterval.Day, startdate, enddate)
Fail again.
Dayinterval.Day and Dayinterval.Dayofyear has a value of 3 and 4 respectively. How come?
This post has been edited by AXRabbit: 15 February 2009 - 10:59 AM
#4
Re: How to calculate number of days between 2 Dates/time
Posted 15 February 2009 - 02:00 PM
I dint get exactly what you're tryin to say but i've got a few suggestions for ya.
1) I think you are misjudging the function
let the output textbox be 'txtResult'
2) Actually, what you are doing in Section2 is WRONG!
You are assigning a value(label.text), to a declared variable 'd', which is USELESS!
the "d" used in datediff function has NO relation with this 'd'(to which you are assigning value of label.text).
USE THIS CODE(well its the old one only but this time i've used YOUR variables) :
If you still have a prob. attach the program and i'll correct it for you.
But PLEASE, try out the above things first!
1) I think you are misjudging the function
let the output textbox be 'txtResult'
txtResult.Text = DateDiff("d", startdate, enddate)
2) Actually, what you are doing in Section2 is WRONG!
You are assigning a value(label.text), to a declared variable 'd', which is USELESS!
the "d" used in datediff function has NO relation with this 'd'(to which you are assigning value of label.text).
USE THIS CODE(well its the old one only but this time i've used YOUR variables) :
Dim startdate As DateTime
Dim enddate As DateTime
startdate = MonthList1.SelectedItem.Text & "/" & DayList1.SelectedItem.Text & "/" & YearList1.SelectedItem.Text & " " & HourList1.SelectedItem.Text & ":" & MinuteList1.SelectedItem.Text
enddate = MonthList2.SelectedItem.Text & "/" & Daylist2.SelectedItem.Text & "/" & YearList2.SelectedItem.Text & " " & HourList2.SelectedItem.Text & ":" & MinuteList2.SelectedItem.Text
'till here we are correct
txtResult.text= "The difference(in days) between the two dates is " & DateDiff("d",startdate, enddate)
'We did it, we did it!!
If you still have a prob. attach the program and i'll correct it for you.
But PLEASE, try out the above things first!
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|