Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
| Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 13th, 2004, 12:47 AM
Registered User
 
Join Date: Aug 2004
Location: Trivandrum, Kerala, India.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Difference between two dates in Vb.net

Hai,
 I have a problem with the difference between two dates.
I need the out put in month.days
ie. for eg:
     2.5 months
With dateDiff function it is not possible.
Can u help me..

Thanking u

regards,

Bimal
  #2 (permalink)  
Old August 13th, 2004, 09:47 AM
Friend of Wrox
Points: 3,489, Level: 24
Points: 3,489, Level: 24 Points: 3,489, Level: 24 Points: 3,489, Level: 24
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Central, NJ, USA.
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Why isn't it possible?

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
  #3 (permalink)  
Old August 13th, 2004, 03:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

As far as I know, the DateDiff function always rounds down to the closest month so 15 weeks would be the same as 16 weeks in terms of months.

Would something like:
--------------------------------------------------------
Dim MonthsDiff as Double

MonthsDiff = FormatNumber(((DateDiff(DateInterval.Day, Date1, date2) / 7) / 4.33), 2)
--------------------------------------------------------

work for you?

J
  #4 (permalink)  
Old August 15th, 2004, 12:23 PM
Registered User
 
Join Date: Aug 2004
Location: Trivandrum, Kerala, India.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai Levy,

Thanks for your reply.
But the problem is still their.
Your solution only give approximate result.
ie. for eg:
Diff b/w 1/1/2003 and 31/12/2003 will give
     result as ==> 12.04 that means 12 months 4 days.
Here actual value is 12 months 0 days
Check it..

Is their any accurate methods.

Hoping to here soon...
Thank you

regards

Bimal
  #5 (permalink)  
Old August 15th, 2004, 09:49 PM
Authorized User
 
Join Date: May 2004
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I never know that there is a method to check date differences. but if I were you, I would do it manually.

  #6 (permalink)  
Old August 15th, 2004, 11:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Actually, that was me that replied, not Hal.

I know it won't be exact but it wasn't supposed to be. Every month has a different number of days to it (28, 30, 31) plus you have to account for leap years, so you will likely have to write a function that does a little more work than this. I thought all you wanted was an estimation of the total months - in your first example (2.5) months or roughly 2 1/2 months.

J


Similar Threads
Thread Thread Starter Forum Replies Last Post
substracting dates in vb.net Yasho VB.NET 2002/2003 Basics 1 May 23rd, 2007 12:37 AM
How to handle dates in VB.net Yasho VB.NET 2002/2003 Basics 3 May 16th, 2007 02:41 PM
Functional Difference Between VB .net And C# Amitchoudhary .NET Framework 2.0 7 September 15th, 2006 08:06 AM
Difference in Dates mcinar Javascript How-To 0 May 8th, 2005 07:08 PM
Difference between VB6.0 and VB.Net-illustrational ramk_1978 General .NET 1 December 31st, 2004 01:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.