Tag Archive | "C#"

Adding Dates and Times in Python

Monday, October 19, 2009

2 Comments

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, […]

Continue reading...

Rounding Numbers in C#

Monday, June 29, 2009

Comments Off on Rounding Numbers in C#

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 […]

Continue reading...

DateDiff Equivalent in C# – 3 Options

Wednesday, April 1, 2009

3 Comments

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 […]

Continue reading...

Working with Null Characters in C# / .Net

Saturday, December 20, 2008

15 Comments

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 […]

Continue reading...