How to check IP Address Validity in C#

Have you ever scrambled around retying to validate an IP Address in C#?

Here’s another way:

private bool isValidIPAddress(string ip)
{
IPAddress address;
return IPAddress.TryParse(ip, out address);
}

Incrementing a datetime field in MS SQL

Use

DATEADD (datepart , number, date )

datepart
Is the parameter that specifies on which part of the date to return a new value. The following table lists the dateparts and abbreviations recognized by Microsoft SQL Server 2005.

Datepart Abbreviations
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
weekday dw, w
hour hh
minute mi, n
second ss, s
millisecond ms
number
Is the value used to increment datepart. If you specify a value that is not an integer, the fractional part of the value is discarded. For example, if you specify day for datepart and1.75 for number, date is incremented by 1
date
Is an expression that returns a datetime or smalldatetime value, or a character string in a date format. For more information about specifying dates, see Date and Time (Transact-SQL).If you specify only the last two digits of the year, values less than or equal to the last two digits of the value of the two digit year cutoff configuration option are in the same century as the cutoff year. Values greater than the last two digits of the value of this option are in the century that comes before the cutoff year. For example, if two-digit year cutoff is 2049 (default), 49 is interpreted as 2049 and 2050 is interpreted as 1950. To avoid ambiguity, use four-digit years.

Returns datetime, but smalldatetime if the date argument is smalldatetime.

Next Page →