PC Review


Reply
Thread Tools Rate Thread

Calculating date differences in C# (DateDiff for c#??)

 
 
Paul Aspinall
Guest
Posts: n/a
 
      23rd Feb 2005
Hi
I want to calculate the difference between 2 dates in C#.

I know there is a function in VB, called DateDiff, but I don't want to ref
the VB library, and want to try to do it natively in C#.

Is there a similar function available in the C# or standard .NET libraries?


Thanks


 
Reply With Quote
 
 
 
 
DalePres
Guest
Posts: n/a
 
      23rd Feb 2005
Look up the Subtraction operator of the DateTime and TimeSpan structures.
You can get the difference between combinations of DateTimes, TimeSpans
returned as either DateTimes or TimeSpans

HTH

DalePres
MCAD, MCDBA, MCSE

"Paul Aspinall" <(E-Mail Removed)> wrote in message
news:%_1Td.160608$(E-Mail Removed)...
> Hi
> I want to calculate the difference between 2 dates in C#.
>
> I know there is a function in VB, called DateDiff, but I don't want to ref
> the VB library, and want to try to do it natively in C#.
>
> Is there a similar function available in the C# or standard .NET
> libraries?
>
>
> Thanks
>
>



 
Reply With Quote
 
Jon Sagara
Guest
Posts: n/a
 
      23rd Feb 2005
Look at System.DateTime and System.TimeSpan.

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

DateTime dtThen = new DateTime (2004, 1, 1);
DateTime dtNow = DateTime.Now;
TimeSpan ts = dtNow - dtThen;

DateTime also contains functions like AddHours & AddMinutes. I don't think
there is any direct equivalent to DateDiff, but you can certainly accomplish
the same thing in other ways using DateTime and TimeSpan.

- Jon



"Paul Aspinall" <(E-Mail Removed)> wrote in message
news:%_1Td.160608$(E-Mail Removed)...
> Hi
> I want to calculate the difference between 2 dates in C#.
>
> I know there is a function in VB, called DateDiff, but I don't want to ref
> the VB library, and want to try to do it natively in C#.
>
> Is there a similar function available in the C# or standard .NET
> libraries?
>
>
> Thanks
>
>



 
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
DateDiff Error Calculating Time if Date Closed is Blank pcover Microsoft Access 11 26th Oct 2009 08:11 AM
Calculating date differences in C# (DateDiff for c#??) Paul Aspinall Microsoft C# .NET 2 23rd Feb 2005 07:45 PM
Calculating Time and Date Differences =?Utf-8?B?RGFycmFu?= Microsoft Excel Programming 2 16th Feb 2005 02:43 PM
Calculating (Date and Time) differences Madcap Microsoft Excel Worksheet Functions 3 28th Apr 2004 12:19 AM
calculating max/min date differences =?Utf-8?B?TWVsaXNzYQ==?= Microsoft Access Form Coding 1 23rd Dec 2003 08:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:31 AM.