PC Review


Reply
Thread Tools Rate Thread

How to calcualte date1 - date2 = # of years?

 
 
RH
Guest
Posts: n/a
 
      26th Feb 2004
Hi,

I would like to calculate the number of years between 2 dates. I tried
using the DateDiff function but I don't get the result that I want. MSDN
says:
If Interval is set to DateInterval.Year, the return value is calculated
purely from the year parts of Date1 and Date2.

I would like the function to consider all of the components of the date (not
just the year portion). I have thought about just getting the number of days
and dividing by 365 but I know I would have to account for leap years.

Any suggestions? Thanks in advance.


 
Reply With Quote
 
 
 
 
Jeremy
Guest
Posts: n/a
 
      26th Feb 2004
Decide what your rules are, then write a function. For instance, how many
years from 1/1/04 to 12/29/04? How about 2/29/04 to 2/28/05?

Does a partial year count at all?

Jeremy

Do you want the answer to be an integer, or would 1.67 be a possible answer?

"RH" <(E-Mail Removed)> wrote in message
news:eP9wq7K$(E-Mail Removed)...
> Hi,
>
> I would like to calculate the number of years between 2 dates. I tried
> using the DateDiff function but I don't get the result that I want. MSDN
> says:
> If Interval is set to DateInterval.Year, the return value is calculated
> purely from the year parts of Date1 and Date2.
>
> I would like the function to consider all of the components of the date

(not
> just the year portion). I have thought about just getting the number of

days
> and dividing by 365 but I know I would have to account for leap years.
>
> Any suggestions? Thanks in advance.
>
>



 
Reply With Quote
 
RH
Guest
Posts: n/a
 
      27th Feb 2004
Thanks. I will define my own rule.

Btw, is there a "standard" for this definition? Does Microsoft have a
standard for this?


"Jeremy" <(E-Mail Removed)> wrote in message
news:epu9LUL$(E-Mail Removed)...
> Decide what your rules are, then write a function. For instance, how many
> years from 1/1/04 to 12/29/04? How about 2/29/04 to 2/28/05?
>
> Does a partial year count at all?
>
> Jeremy
>
> Do you want the answer to be an integer, or would 1.67 be a possible

answer?
>
> "RH" <(E-Mail Removed)> wrote in message
> news:eP9wq7K$(E-Mail Removed)...
> > Hi,
> >
> > I would like to calculate the number of years between 2 dates. I tried
> > using the DateDiff function but I don't get the result that I want. MSDN
> > says:
> > If Interval is set to DateInterval.Year, the return value is calculated
> > purely from the year parts of Date1 and Date2.
> >
> > I would like the function to consider all of the components of the date

> (not
> > just the year portion). I have thought about just getting the number of

> days
> > and dividing by 365 but I know I would have to account for leap years.
> >
> > Any suggestions? Thanks in advance.
> >
> >

>
>



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      27th Feb 2004
Hi RH,

Have a look at the dateInteveral.subtract method and the
dateInterval.add.... methodes

It uses methods instead of properties and operators, therefore it looks a
little bit strange but it is easy to do.

As a very simple sample
\\\\
Dim span As TimeSpan = CDate("06/06/2003 12:00").Subtract(Now)
////

But there are a lot of posibilities

I hope this helps,

Cor

>
> I would like to calculate the number of years between 2 dates. I tried
> using the DateDiff function but I don't get the result that I want. MSDN
> says:
> If Interval is set to DateInterval.Year, the return value is calculated
> purely from the year parts of Date1 and Date2.
>
> I would like the function to consider all of the components of the date

(not
> just the year portion). I have thought about just getting the number of

days
> and dividing by 365 but I know I would have to account for leap years.
>
> Any suggestions? Thanks in advance.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting if Date1 is after and Date2 is before another date Mally Microsoft Excel Misc 5 1st Sep 2008 09:03 PM
Name The Day Of The Date2 Mathew P Bennett Microsoft Excel Misc 5 10th Jul 2008 09:58 AM
Re: datediff("m",date1,date2)does not work on any date other than the John Spencer Microsoft Access Queries 3 6th Dec 2006 10:28 PM
setting date 2 to be 365 days later than date1 Scott Microsoft VB .NET 2 24th Mar 2005 03:18 PM
Days Between date1 and current date =?Utf-8?B?THVrZQ==?= Microsoft Access Queries 4 28th Jan 2005 02:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:05 PM.