<?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>DotBert &#187; isdatetime</title>
	<atom:link href="http://dotbert.loedeman.nl/category/isdatetime/feed" rel="self" type="application/rss+xml" />
	<link>http://dotbert.loedeman.nl</link>
	<description>.NET thoughts by Bert Loedeman</description>
	<lastBuildDate>Wed, 19 Oct 2011 07:57:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>IsDateTime in .NET for both ticks and string representation</title>
		<link>http://dotbert.loedeman.nl/isdatetime-in-net-for-both-ticks-and-string-representation</link>
		<comments>http://dotbert.loedeman.nl/isdatetime-in-net-for-both-ticks-and-string-representation#comments</comments>
		<pubDate>Fri, 09 Jun 2006 09:16:00 +0000</pubDate>
		<dc:creator>Bert Loedeman</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[datetime check]]></category>
		<category><![CDATA[datetime ticks]]></category>
		<category><![CDATA[expression]]></category>
		<category><![CDATA[isdatetime]]></category>

		<guid isPermaLink="false">http://www.loedeman.net/wordpress/?p=14</guid>
		<description><![CDATA[Some while ago I developed a Settings system, where the SettingValue type should be checked. The DateTime.TryParse function did not do all the work I wanted it to do, so I thought &#8216;why not develop my own workaround&#8217; ? It is posted below&#8230;]]></description>
			<content:encoded><![CDATA[<p>Some while ago I developed a Settings system, where the SettingValue type should be checked. The DateTime.TryParse function did not do all the work I wanted it to do, so I thought &#8216;why not develop my own workaround&#8217; <img src='http://dotbert.loedeman.nl/wp-includes/images/smilies/icon_smile.gif' alt="IsDateTime in .NET for both ticks and string representation icon smile" class='wp-smiley' title="IsDateTime in .NET for both ticks and string representation" />  ? It is posted below&#8230;</p>
<pre class="brush: csharp; title: ; notranslate">
/// &lt;summary&gt;
/// The IsDateTime function returns whether the given expression is a DateTime or not.
/// &lt;/summary&gt;
/// &lt;param name=&quot;expression&quot;&gt;Expression to check for being DateTime.&lt;/param&gt;
/// &lt;returns&gt;Boolean&lt;/returns&gt;
/// &lt;remarks&gt;
/// The DateTime expression can be given as ticks or as normal DateTime representation.
/// &lt;/remarks&gt;
public static bool IsDateTime(object expression) {
if(expression == null) return false;Bert Loedeman

string stringExpression = System.Convert.ToString(expression);
if(String.IsNullOrEmpty(stringExpression)) return false;

// DateTime can be specified in ticks. In that case the string should be convertible
// to a long (System.Int64) and fit in a specific range.
long retLong;
if(Int64.TryParse(stringExpression, out retLong)) {
// Ticks: 0 = DateTime.MinValue, 0x2bca2875f4373fff = DateTime.MaxValue
if((retLong &lt; DateTime.MinValue.Ticks) || (retLong &gt; DateTime.MaxValue.Ticks)) return false;
return true;
}

DateTime retDateTime;
return DateTime.TryParse(stringExpression, out retDateTime);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://dotbert.loedeman.nl/isdatetime-in-net-for-both-ticks-and-string-representation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

