<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pressing the Red Button &#187; DateDiff</title>
	<atom:link href="http://www.pressthered.com/tag/datediff/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pressthered.com</link>
	<description>Adventures in Software Development</description>
	<lastBuildDate>Sun, 08 Jan 2012 21:28:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>DateDiff Equivalent in C# &#8211; 3 Options</title>
		<link>http://www.pressthered.com/datediff_equivalent_in_c_-_3_options/</link>
		<comments>http://www.pressthered.com/datediff_equivalent_in_c_-_3_options/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 07:00:50 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DateDiff]]></category>
		<category><![CDATA[DateTime]]></category>

		<guid isPermaLink="false">http://www.pressingtheredbutton.com/?p=76</guid>
		<description><![CDATA[If you are looking for a DateDiff function in C# like in VB or SQL Server, there is none. However here are some options to perform date operations in .Net via C#. Option 1 You can subtract two DateTime objects which returns a TimeSpan object. Here is an example: //To get the amount of days [...]]]></description>
			<content:encoded><![CDATA[<p>If you are looking for a DateDiff function in C# like in VB or SQL Server, there is none. However here are some options to perform date operations in .Net via C#.</p>
<p><strong>Option 1</strong><br />
You can subtract two DateTime objects which returns a TimeSpan object. Here is an example:</p>
<pre name="code" class="c-sharp">
//To get the amount of days between two dates.
DateTime date1 = new DateTime(2007,1,1);
DateTime date2 = DateTime.Today;
int daysDiff = ((TimeSpan) (date2 - date1)).Days;
</pre>
<p>This is possible via operator overloading. Here are the MSDN docs on <a href="http://msdn.microsoft.com/en-us/library/system.datetime.op_addition.aspx">addition</a> and <a href="http://msdn.microsoft.com/en-us/library/system.datetime.op_subtraction.aspx">subtraction</a>.</p>
<p><strong>Option 2</strong><br />
Write you own DateDiff function. <a href="http://www.aspcode.net/C-Datediff.aspx">Of course somebody already has</a>. Just copy and paste.</p>
<p><strong>Option 3</strong><br />
For VB fans, you can reference the Microsoft.VisualBasic dll and access the VB DateDiff function directly. <a href="http://www.aspcode.net/C-Datediff.aspx">See the example on this page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/datediff_equivalent_in_c_-_3_options/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

