Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No of days from date X ? 3

Status
Not open for further replies.

eequalsmc2plus1

Programmer
Aug 26, 2002
28
ZA
Hi

Does anyone know of a way or function to get the number of days between 2 specific dates
eg: date 1 1 July 2002
date 2 10 July 2002
It will give me 9
but that simple example
need it to work with different months and leap years and all
eg: date 1 31 December 1967
date 2 10 December 2002
Answer is 12763
Can do that with 1 line in other language( UniVerse Basic )
but need to do it in VB.
Could probably do it by getting years and * 365 and then and divide by 4 and add that for leap years and then work out months, but was wondering if easier way.

Thanks
Damian
 
if you lookup DateDiff in MSDN or this forum, you will find loads of examples

Matt
 
Try the Datediff function

Msgbox Datediff("d", "31 dec 1967", "10 Dec 2002")
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thank you both for the QUICK response, not even 5 minutes.
I was about to start working it out the long way.

Thanks, saved me lots of work.
 

If the dates are stored in date variables:
?Date1 - Date2

If the dates are stored in string variables:
?CDate(Date1) - CDate(Date2)

For raw dates:
?#10 December 2002#-#31 December 1967#

These are the fastest methods [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Another question. This I think a bit more complicated.

Just let me explain something quick.
In UniVerse Basic the date 10 December 2002 is stored as 12763, it gets this number by taking the number of days from 31 December 1967, when it was made it think.

So now to store a date I get the user to enter whatever they want, a normal date, then I use
DATEDIFF("d","31 dec 1967",USER_DATE) it will put the date into the format I need to store it.
Now, if I read a date and want to display it in normal format ??? How you do that ?
Looked at DATEDIFF, it not got anything 2 do with it.

So basically UniVerse Basic takes 31 December 1967 and adds 12763 days to get 10 December 2002 ? How can you do that in VB ?

Thanks 4 any help,
Damian
 

Look up the DateAdd function in VB Help,

or

Date1 + 12763

Use the Format() or FormatDateTime() functions in VB Help to give the date a different format. [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Perfect.
Thanks everyone, got what I needed.

And you each get a * for doing your homework so quickly and getting it right.

Bye
 


Thanks. Were glad to help! [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top