473,465 Members | 4,818 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datediff

Hi

When I use datediff, the Year I get back is not correct .At msdn I found the problem.(From 31/12/2003 to 1/1/2004 I get 1Year butt this is not correct.
Where can I find a function that give's me the exact Year ( for 31/12/2003 to 1/1/2004 this is 0 Year

Thx

JoskeXP
Nov 20 '05 #1
5 2771
Hi Joske,

Have a look at the timespan

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps better?

Cor
Nov 20 '05 #2
"JoskeXP" <an*******@discussions.microsoft.com> schrieb

When I use datediff, the Year I get back is not correct .At msdn I
found the problem.(From 31/12/2003 to 1/1/2004 I get 1Year butt this
is not correct.) Where can I find a function that give's me the exact
Year ( for 31/12/2003 to 1/1/2004 this is 0 Year)


2004 - 2003 = 1

How long is one year? 365 or 366 days? How long is one month? 28, 29, 30 or
31 days?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
* "=?Utf-8?B?Sm9za2VYUA==?=" <an*******@discussions.microsoft.com> scripsit:
I need this because I have to now of he's at least 21 year's old.
When I do 1/1/2004 - 31/12/2003 I get 1 Year but it's only 1 day difference.
When he's 20 Year 11 Months and 25 day's I only need 20 Year and noy 21 Year


By subtracting the dates, you get a 'TimeSpan'. Check the number of
days the timespan includes.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
"JoskeXP" <an*******@discussions.microsoft.com> schrieb

I need this because I have to now of he's at least 21 year's old.
When I do 1/1/2004 - 31/12/2003 I get 1 Year but it's only 1 day
difference. When he's 20 Year 11 Months and 25 day's I only need 20
Year and noy 21 Year

Public Function GetAge( _
ByVal BirthDate As Date, ByVal ReferenceDate As Date) As Integer

GetAge = ReferenceDate.Year - BirthDate.Year

If ReferenceDate.Month < BirthDate.Month _
OrElse (ReferenceDate.Month = BirthDate.Month _
AndAlso ReferenceDate.Day < BirthDate.Day) Then
GetAge -= 1
End If

End Function
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
Hi

It works perfect. Thank yo

Joskexp
Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: CJM | last post by:
I have an ASP page that lists files and folders in a directory. I'm using a cookie to record the last time this page was visited, and I intend to show links that are created/modified from that date...
8
by: inamori | last post by:
I face that problems 07/01/2003 06/30/2006 ---------> it should be 3 01/01/2003 02/28/2005 --------->could i get 2 years and 2 months 01/01/2003 03/01/2005 ...
6
by: Lofty | last post by:
Hi all. I have to write an app that interacts with mySQL (I really must have done some evil, evil stuff in a previous life to be landed with this!) I need to work out the difference in days...
1
by: intl04 | last post by:
I'm trying to set up a query that will include a new field ('Days until completion') whose value is derived from the DateDiff function. I think I have the syntax correct but am not sure. Days...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
5
by: sr | last post by:
Anyone know of a better way to simulate a datediff for C#, i.e., without referencing the VB.NET runtime? Only added the functionality that was needed for me so it is not the full implementation...
6
by: kevinjwilson | last post by:
I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
2
by: muddasirmunir | last post by:
i am using vb 6 , i had place two datepicker in form now i want to calcuate differcen of month in two date for this i used the function datediff i had try it withh many syntax but getting error...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
0
agi2029
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,...
0
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.