Hi everyone,
is there a function that calculates the exact amount of Years, Months, and
Days between two days?
TimeDiff is not good enough, since it calculates, for example:
Date 1: Dec. 31st 2003
Date 2: Jan 1st 2004
The real difference is 0 years, 0 months, 1 day. DateDiff returns 1 year, 1
month, 1 day.
Is there a funcion, or rutine, or does anyone know a good way to achieve the
desired result?
Thanks, from Spain 5 8823
Hi Juan,
Try subtracting two DateTime variables and you'll end up with TimeSpan
structure.
--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com www.rthand.com
"Juan" <ju*********@ho tmail.com> wrote in message
news:OB******** ******@TK2MSFTN GP10.phx.gbl... Hi everyone,
is there a function that calculates the exact amount of Years, Months, and Days between two days?
TimeDiff is not good enough, since it calculates, for example:
Date 1: Dec. 31st 2003 Date 2: Jan 1st 2004
The real difference is 0 years, 0 months, 1 day. DateDiff returns 1 year,
1 month, 1 day.
Is there a funcion, or rutine, or does anyone know a good way to achieve
the desired result?
Thanks, from Spain
Subtract one datetime from another to return a TimeSpan. You can get the
time accurate to the millisecond.
--
Bob Powell [MVP]
Visual C#, System.Drawing
All you ever wanted to know about ListView custom drawing is in Well Formed. http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/gdiplus_faq.htm
*RSS*RSS*RSS*RS S*RSS*RSS*RSS*R SS*RSS*RSS*RSS* RSS*RSS*
The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41
*RSS*RSS*RSS*RS S*RSS*RSS*RSS*R SS*RSS*RSS*RSS* RSS*RSS*
"Juan" <ju*********@ho tmail.com> wrote in message
news:OB******** ******@TK2MSFTN GP10.phx.gbl... Hi everyone,
is there a function that calculates the exact amount of Years, Months, and Days between two days?
TimeDiff is not good enough, since it calculates, for example:
Date 1: Dec. 31st 2003 Date 2: Jan 1st 2004
The real difference is 0 years, 0 months, 1 day. DateDiff returns 1 year,
1 month, 1 day.
Is there a funcion, or rutine, or does anyone know a good way to achieve
the desired result?
Thanks, from Spain
But I can´t get the numbers of years and mohts transcurred from a TimeSpan,
only the number of days, and that doesn´t solve the Dec 31st 2001 to Jan 1st
2004 problem. I will find out the number of days, but not the number of
months or years.
Bob Powell [MVP] wrote:
:: Subtract one datetime from another to return a TimeSpan. You can get
:: the time accurate to the millisecond.
::
:: --
:: Bob Powell [MVP]
:: Visual C#, System.Drawing
::
:: All you ever wanted to know about ListView custom drawing is in Well
:: Formed. http://www.bobpowell.net/currentissue.htm
::
:: Answer those GDI+ questions with the GDI+ FAQ
:: http://www.bobpowell.net/gdiplus_faq.htm
::
:: *RSS*RSS*RSS*RS S*RSS*RSS*RSS*R SS*RSS*RSS*RSS* RSS*RSS*
::
:: The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml
:: Windows Forms Tips and Tricks:
:: http://www.bobpowell.net/tipstricks.xml Bob's Blog:
:: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41
::
:: *RSS*RSS*RSS*RS S*RSS*RSS*RSS*R SS*RSS*RSS*RSS* RSS*RSS*
::
::
::
::
::
:: "Juan" <ju*********@ho tmail.com> wrote in message
:: news:OB******** ******@TK2MSFTN GP10.phx.gbl...
::: Hi everyone,
:::
::: is there a function that calculates the exact amount of Years,
::: Months, and Days between two days?
:::
::: TimeDiff is not good enough, since it calculates, for example:
:::
::: Date 1: Dec. 31st 2003
::: Date 2: Jan 1st 2004
:::
::: The real difference is 0 years, 0 months, 1 day. DateDiff returns 1
::: year, 1 month, 1 day.
:::
::: Is there a funcion, or rutine, or does anyone know a good way to
::: achieve the desired result?
:::
::: Thanks, from Spain
"Juan" <ju*********@ho tmail.com> wrote in message
news:OB******** ******@TK2MSFTN GP10.phx.gbl... Hi everyone,
is there a function that calculates the exact amount of Years, Months, and Days between two days?
TimeDiff is not good enough, since it calculates, for example:
Date 1: Dec. 31st 2003 Date 2: Jan 1st 2004
The real difference is 0 years, 0 months, 1 day. DateDiff returns 1 year,
1 month, 1 day.
Is there a funcion, or rutine, or does anyone know a good way to achieve
the desired result?
You need to think a little more about whether your "desired result" makes
sense.
Months and Years are not fixed Timespans. Given 2 DateTime's the rule for
DateDiff is, and has to be, that the difference in years between the 2 dates
is the number of times you cross the "year boundary" (Jan 1st 12:00 am),
when traveling from the first date to the second.
Other rules are sometimes used, but they have their own difficulties.
For instance what is the difference in months between
Date 1: Jan. 31st 2003
Date 2: Feb. 28st 2003
?
The interval is 28 days long.
January has 31 days, so is the differnece is 0?
February has 28 days, so is the differnece is 1?
Or is a month defined as a 30 day timespan, so is the difference is 0?
What about
Date 1: Jan. 31st 2004
Date 2: Feb. 28st 2004
?
January has 31 days, and February has 29 days so is the difference is 0?
And what about
Date 1: Feb. 28st 2003
Date 2: Jan. 31st 2003
?
is DateDiff(d1,d2) = -DateDiff(d2,d1) ?
David
Juan wrote: But I can´t get the numbers of years and mohts transcurred from a TimeSpan, only the number of days, and that doesn´t solve the Dec 31st 2001 to Jan 1st 2004 problem. I will find out the number of days, but not the number of months or years.
you can use VB.NET's DateDiff() function. Either wrap it in a class
that you can easily call from C# or call it directly by referencing the
Microsoft.Visua lBasic assembly - it's in the
Microsoft.Visua lBasic.DateAndT ime class. Bob Powell [MVP] wrote: :: Subtract one datetime from another to return a TimeSpan. You can get :: the time accurate to the millisecond. :: :: -- :: Bob Powell [MVP] :: Visual C#, System.Drawing :: :: All you ever wanted to know about ListView custom drawing is in Well :: Formed. http://www.bobpowell.net/currentissue.htm :: :: Answer those GDI+ questions with the GDI+ FAQ :: http://www.bobpowell.net/gdiplus_faq.htm :: :: *RSS*RSS*RSS*RS S*RSS*RSS*RSS*R SS*RSS*RSS*RSS* RSS*RSS* :: :: The GDI+ FAQ: http://www.bobpowell.net/faqfeed.xml :: Windows Forms Tips and Tricks: :: http://www.bobpowell.net/tipstricks.xml Bob's Blog: :: http://royo.is-a-geek.com/siteFeeder...aspx?FeedId=41 :: :: *RSS*RSS*RSS*RS S*RSS*RSS*RSS*R SS*RSS*RSS*RSS* RSS*RSS* :: :: :: :: :: :: "Juan" <ju*********@ho tmail.com> wrote in message :: news:OB******** ******@TK2MSFTN GP10.phx.gbl... ::: Hi everyone, ::: ::: is there a function that calculates the exact amount of Years, ::: Months, and Days between two days? ::: ::: TimeDiff is not good enough, since it calculates, for example: ::: ::: Date 1: Dec. 31st 2003 ::: Date 2: Jan 1st 2004 ::: ::: The real difference is 0 years, 0 months, 1 day. DateDiff returns 1 ::: year, 1 month, 1 day. ::: ::: Is there a funcion, or rutine, or does anyone know a good way to ::: achieve the desired result? ::: ::: Thanks, from Spain
--
mikeb This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bambero |
last post by:
Hello all
Problem like in subject. There is no problem when I want to count days
between two dates. Problem is when I want to count years becouse of
leap years.
For ex.
between
2002-11-19 2003-11-19
|
by: MMFBprez |
last post by:
I am trying to compute storage charges by getting the number of months
between dates and multiplying it by a rate. I cannot get a correct
number of months if the date is greater than a year ago. Here is the
formula I am using now to get the number of months: #ofMonths:
Month(.-.)-1.
It has worked for me until now because it never was greater than a
year before. Please help. I am a novice at this.
|
by: carl.barrett |
last post by:
Hi,
I have a continuous form based on a query ( I will also be creating a
report based on the same query).
There are 2 fields:
Date Obtained and Date Of Expiry
I want a further 3 columns to the right of these 2 fields to show the
|
by: ann |
last post by:
is there someway to disable the Other Months day(the previous and next months
days) s from appearing?
If so, can you let me know how?
Thanks so much for your help!
|
by: jpr |
last post by:
Friends, I have a form with four fields, date1, date2, date3 and date4.
All these have all a mm/dd/yyyy format and have their source to a
table.
I need to add an unbound control (I will name it txtresult) which will
count in months and years the difference between the dates.
Ex.
date1: 01/01/1970
| |
by: Jose |
last post by:
Exists a function that determined between two dates the years,months and
days?
Thanks a lot.
|
by: thebjorn |
last post by:
For the purpose of finding someone's age I was looking for a way to
find how the difference in years between two dates, so I could do
something like:
age = (date.today() - born).year
but that didn't work (the timedelta class doesn't have a year
accessor).
I looked in the docs and the cookbook, but I couldn't find anything, so
|
by: karthickkuchanur |
last post by:
Hai sir,
i assigned to calculate the age from current date ,i have the date of birth of employee from that i have to calculate the age dynamically,
i refer to google it was confusing me .please give some idea to do sir
|
by: johanneguaybenoit |
last post by:
Hi
I would like to know how to create a function or module to calculate
the age of a person in years months days.
and hours if feasable
But I really nead to know in years months days.
I am waiting a reply from you and many thanks for your help in advance.
Johanne
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |