<?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; C#</title>
	<atom:link href="http://www.pressthered.com/tag/c/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>Adding Dates and Times in Python</title>
		<link>http://www.pressthered.com/adding_dates_and_times_in_python/</link>
		<comments>http://www.pressthered.com/adding_dates_and_times_in_python/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 06:11:03 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=645</guid>
		<description><![CDATA[Using the built-in modules datetime and timedelta, you can perform date and time addition/subtraction in python: from datetime import datetime from datetime import timedelta #Add 1 day print datetime.now() + timedelta(days=1) #Subtract 60 seconds print datetime.now() - timedelta(seconds=60) #Add 2 years print datetime.now() + timedelta(days=730) #Other Parameters you can pass in to timedelta: # days, [...]]]></description>
			<content:encoded><![CDATA[<p>Using the built-in modules <strong>datetime</strong> and <strong>timedelta</strong>, you can perform date and time addition/subtraction in <strong>python</strong>:</p>
<pre name="code" class="python">
from datetime import datetime
from datetime import timedelta

#Add 1 day
print datetime.now() + timedelta(days=1)

#Subtract 60 seconds
print datetime.now() - timedelta(seconds=60)

#Add 2 years
print datetime.now() + timedelta(days=730)

#Other Parameters you can pass in to timedelta:
# days, seconds, microseconds,
# milliseconds, minutes, hours, weeks

#Pass multiple parameters (1 day and 5 minutes)
print datetime.now() + timedelta(days=1,minutes=5)
</pre>
<p>Here is a python reference that gives more examples and advanced features:<br />
<a href="http://docs.python.org/library/datetime.html">http://docs.python.org/library/datetime.html</a></p>
<p>If you are coming from a .net or sql environment, here are the above examples in C# and SQL (Microsoft) for comparison:<br />
<strong>C#</strong></p>
<pre name="code" class="c#">
DateTime myTime = new DateTime();

--Add 1 day
myTime.AddDays(1);

--Subtract 60 seconds
myTime.AddSeconds(-60);

--Add 2 years
myTime.AddYears(2);
</pre>
<p><strong>SQL</strong></p>
<pre name="code" class="sql">
--Add 1 day
select DATEADD(day, 1, getdate())

--Subtract 60 seconds
select DATEADD(second, -60, getdate())

--Add 2 years
select DATEADD(Year, 2, getdate())
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/adding_dates_and_times_in_python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rounding Numbers in C#</title>
		<link>http://www.pressthered.com/rounding_numbers_in_c/</link>
		<comments>http://www.pressthered.com/rounding_numbers_in_c/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 06:51:44 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=396</guid>
		<description><![CDATA[A quick overview on rounding numbers in C# with examples: // To Round 3.1415 to nearest integer -> 3 decimal result1 = Math.Round(3.1415m); // To Round 3.1415 to the third decimal place -> 3.142 decimal result2 = Math.Round(3.1415m, 3); // To Round 18.5m Up -> 19 decimal result3 = Math.Round(18.5m, 0, MidpointRounding.AwayFromZero); // The default [...]]]></description>
			<content:encoded><![CDATA[<p>A quick overview on <strong>rounding numbers in C#</strong> with examples:</p>
<pre name="code" class="c-sharp">
// To Round 3.1415 to nearest integer -> 3
decimal result1 = Math.Round(3.1415m);

// To Round 3.1415 to the third decimal place -> 3.142
decimal result2 = Math.Round(3.1415m, 3);

// To Round 18.5m Up -> 19
decimal result3 = Math.Round(18.5m, 0, MidpointRounding.AwayFromZero);

// The default will round down (ToEven) -> 18
decimal result4 = Math.Round(18.5m, 0);
</pre>
<p>One advantage of the default for mid point rounding down, is if you are working with numerous fractions, the sums could be more accurate (if you keep rounding up all your numbers it could skew your results).  </p>
<p><strong>More Information:</strong><br />
You can round numbers of type decimal or double using .Net&#8217;s System.Math.Round() method. Returns a decimal. See <a href="http://msdn.microsoft.com/en-us/library/system.math.round.aspx">MSDN doc</a> for additional reference.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/rounding_numbers_in_c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
		<item>
		<title>Working with Null Characters in C# / .Net</title>
		<link>http://www.pressthered.com/working_with_null_characters_in_c_net/</link>
		<comments>http://www.pressthered.com/working_with_null_characters_in_c_net/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 05:26:30 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.pressingtheredbutton.com/?p=49</guid>
		<description><![CDATA[Here is one method to manipulate Null characters in C#: To Search a String for a Null character: mystring.Contains(Convert.ToChar(0x0).ToString() ); //The hexidecimal 0x0 is the null character To Replace all Null Characters in a String: mystring.Replace(Convert.ToChar(0x0).ToString(), ""); Why Do I Need This? It might help. I needed it when I got a nasty error message [...]]]></description>
			<content:encoded><![CDATA[<p>Here is one method to manipulate Null characters in C#:</p>
<p><strong>To Search a String for a Null character:</strong></p>
<pre name="code" class="c-sharp">
mystring.Contains(Convert.ToChar(0x0).ToString() );
//The hexidecimal 0x0 is the null character
</pre>
<p><strong>To Replace all Null Characters in a String:</strong></p>
<pre name="code" class="c-sharp">
mystring.Replace(Convert.ToChar(0x0).ToString(), "");
</pre>
<p><strong>Why Do I Need This?</strong><br />
It might help. I needed it when I got a nasty error message in a data layer that was using asp.net web services and soap to retrieve the data:<br />
&#8220;There is an error in XML document  hexadecimal value 0&#215;00, is an invalid character&#8221;<br />
Basically what happened is that a null character was pasted into a SQL Server database via an Access front end. When my asp.net app was pulling the data via a SOAP data layer, the null character can not be used in a XML document with UTF encoding. Which is the transport method of this particualr service. So the quick hack was to strip out the null character after the data pull but before the soap transfer back to the client.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/working_with_null_characters_in_c_net/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

