3 Replies - 19371 Views - Last Post: 15 February 2009 - 02:00 PM Rate Topic: -----

#1 AXRabbit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 04-February 09

How to calculate number of days between 2 Dates/time

Posted 11 February 2009 - 04:15 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: How to calculate number of days between 2 Dates/time

#2 Nikhil_07n  Icon User is offline

  • The cheese stands alone..
  • member icon

Reputation: 49
  • View blog
  • Posts: 2,489
  • Joined: 09-January 09

Re: How to calculate number of days between 2 Dates/time

Posted 11 February 2009 - 12:56 PM

Use the library function "DateAdd"


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
Was This Post Helpful? 0
  • +
  • -

#3 AXRabbit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 04-February 09

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?

This post has been edited by AXRabbit: 15 February 2009 - 10:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 Nikhil_07n  Icon User is offline

  • The cheese stands alone..
  • member icon

Reputation: 49
  • View blog
  • Posts: 2,489
  • Joined: 09-January 09

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'


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!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1