954,582 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VB/Access - Difference between two dates

Hi

In my VB program, I am going through a database, adding each row/record to a listview. One of these fields is a date. For each row/record, I want to get the difference in days between that date, and the corresponding date in the next row/record.

Thanks
Robert

robertlees
Newbie Poster
20 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

Hi,

You could use the DateDiff command.

Syntax:
DateDiff(interval,date1,date2)

e.g.
DaysLeft = DateDiff("d",Now,"25/12/2005")
MonthsLeft = DateDiff("m",Now,"25/12/2005")


pG

purplegerbil
Junior Poster in Training
78 posts since Apr 2005
Reputation Points: 24
Solved Threads: 6
 

Hi

Thanks for the quick reply. However, the tricky bit is how to get the difference between dates where the dates are in different records from an SQL SELECT. I'm going through a "Do Until .GotLastRow()" loop, and imagine that in each iteration, I can somehow get the next row, use the date and do the datedif with the first date, then move back to the previous row. Is this possible, or is there some other method?

Thanks
Robert

robertlees
Newbie Poster
20 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

ADO allows you to use the MoveNext / MovePrevious methods on a recordset allowing you to move back and forth as much as you like.

mnemtsas
Posting Whiz in Training
200 posts since Jul 2004
Reputation Points: 16
Solved Threads: 1
 

Thanks for your answer Mark. I would like to do what you suggest, but I am missing something here. My object doesn't have MoveNext etc in it's list of methods. Do I have to open the database with a different method, or class. How to I get the results of my SQL SELECT appear as a RecordSet ?

Thanks
Robert

robertlees
Newbie Poster
20 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

HOw are you opening your recordset? ADO or RDO?

mnemtsas
Posting Whiz in Training
200 posts since Jul 2004
Reputation Points: 16
Solved Threads: 1
 

Hi Mark

My open is...
Set objDB = New clsDataSource
objDB.OpenIt (strFile)
The class looks like..
clsDataSource(ADODataSource.cls)

Is that enough to tell you what I am doing wrong?

Thanks Mark

Robert

robertlees
Newbie Poster
20 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

No. Someone has written a wrapper for some of the ADO stuff by the look of things. What methods are available?

mnemtsas
Posting Whiz in Training
200 posts since Jul 2004
Reputation Points: 16
Solved Threads: 1
 

Hi Mark

Here are the methods I get from the drop-down list

CloseIt
ColumnExists
DateDelim
GetColumnAttributes
GetColumnCount
GetColumnName
GetColumnSize
GetColumnType
GetColumnValue
GetNextRow
GotLastRow
LastError
OpenIt
PerformSQL
SetColumnValue
SQL
ValueOfFalse
ValueOfTrue
WriteToLogFile

Thanks
Robert

robertlees
Newbie Poster
20 posts since Sep 2005
Reputation Points: 10
Solved Threads: 0
 

GetNextRow looks like it does something. Is there a 'GetPreviousRow' or something? If there isn't it would be pretty trivial to add this to the class. Just copy the GetNextRow code, change the procedure name, and change the method used to 'MovePrevious' instead of MoveNext. There'll probably be a check for EOF that you'll need to change to BOF too.

mnemtsas
Posting Whiz in Training
200 posts since Jul 2004
Reputation Points: 16
Solved Threads: 1
 

hi
In my VB program, when we select a day from a calendar and it should show what the day and month it will be after 90 days from the current date.... hope you al can guide me to complete my promblem.. waiting 4 your reply...

Thank you..

johntup
Newbie Poster
1 post since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

use the dateadd function


Good Luck

vb5prgrmr
Posting Virtuoso
1,912 posts since Mar 2009
Reputation Points: 156
Solved Threads: 296
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You