<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - C# Sting converstion</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - C# Sting converstion</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Mon, 20 May 2013 09:37:46 GMT</pubDate>
	<lastBuildDate>Mon, 20 May 2013 09:37:46 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>28</c9:totalResults>
	<c9:pageCount>-28</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p>Hi I know its a simple question, but I was wondering how to convert a int (date) to a string in c#. I have just started c# after using VB for some time.</p>
<p>&nbsp;</p>
<p>Gregor.</p>
<p>&nbsp;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/516010#516010</link>
		<pubDate>Sat, 26 Dec 2009 12:42:34 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/516010#516010</guid>
		<dc:creator>peoples</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/peoples/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p>An &quot;int&quot; date?</p>
<p>&nbsp;</p>
<p>If you've got a DateTime instance, just call myDate.ToString(); you can optionally specify a format-string or predefined culture settings to get the right format (e.g. myDate.ToString(&quot;yyyy-MM-dd&quot;); or myDate.ToString(CultureInfo.CurrentCulture); )</p>
<p>&nbsp;</p>
<p>In .NET, every class inherits Object's .ToString() method, by default this method simply returns some basic information gained from Reflection, but some types (such as DateTime) override the behaviour. There is also the System.Convert class, but I find myself
 rarely using it (since it's nothing you can't do with the existing .TryParse / .Parse / .ToString methods.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/b91af08e8fb94efc964d9deb000b23ba#b91af08e8fb94efc964d9deb000b23ba</link>
		<pubDate>Sat, 26 Dec 2009 13:04:35 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/b91af08e8fb94efc964d9deb000b23ba#b91af08e8fb94efc964d9deb000b23ba</guid>
		<dc:creator>W3bbo</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/W3bbo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">W3bbo said:</div><div class="quoteText">
<p>An &quot;int&quot; date?</p>
<p>&nbsp;</p>
<p>If you've got a DateTime instance, just call myDate.ToString(); you can optionally specify a format-string or predefined culture settings to get the right format (e.g. myDate.ToString(&quot;yyyy-MM-dd&quot;); or myDate.ToString(CultureInfo.CurrentCulture); )</p>
<p>&nbsp;</p>
<p>In .NET, every class inherits Object's .ToString() method, by default this method simply returns some basic information gained from Reflection, but some types (such as DateTime) override the behaviour. There is also the System.Convert class, but I find myself
 rarely using it (since it's nothing you can't do with the existing .TryParse / .Parse / .ToString methods.</p>
</div></blockquote>
<p>Yeah I wonder if the OP meant:</p>
<p>&nbsp;</p>
<p>an International Date ?</p>
<p>or possibly some long int format like 12252009 ?</p>
<p>&nbsp;</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/fc7b37b7449d434ab10c9deb000b23e7#fc7b37b7449d434ab10c9deb000b23e7</link>
		<pubDate>Sat, 26 Dec 2009 15:06:58 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/fc7b37b7449d434ab10c9deb000b23e7#fc7b37b7449d434ab10c9deb000b23e7</guid>
		<dc:creator>figuerres</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/figuerres/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">figuerres said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">W3bbo said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Yeah I wonder if the OP meant:</p>
<p>&nbsp;</p>
<p>an International Date ?</p>
<p>or possibly some long int format like 12252009 ?</p>
<p>&nbsp;</p>
</div></blockquote>
<p>If its a date or time value stored in an integer representation of something like ticks or miliseconds then it's trivial, just multiply and cast to long to get ticks, then use DateTime's ticks constructor.</p>
<p>&nbsp;</p>
<p>If it's something like 25122009 then the OP has my sympathy, how does something like that happen?</p>
<p>&nbsp;</p>
<p>Well, if it is like 25122009 then convert it to a digit array (might as well just convert to a string) then extract the bits you need, then convert to int or datetime:</p>
<p>&nbsp;</p>
<p>String input = 25122009.ToString();</p>
<p>String dayStr = input.Substring(0,2);</p>
<p>String monStr = input.Substring(2,2);</p>
<p>String yerStr = input.Substring(4,4);</p>
<p>&nbsp;</p>
<p>DateTime date = new DateTime( int.Parse( dayStr ), int.Parse(monStr), int.Parse(yerStr) );</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/84f201b20b8c4e1996ca9deb000b2414#84f201b20b8c4e1996ca9deb000b2414</link>
		<pubDate>Sat, 26 Dec 2009 15:39:09 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/84f201b20b8c4e1996ca9deb000b2414#84f201b20b8c4e1996ca9deb000b2414</guid>
		<dc:creator>W3bbo</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/W3bbo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">W3bbo said:</div><div class="quoteText">
<p>An &quot;int&quot; date?</p>
<p>&nbsp;</p>
<p>If you've got a DateTime instance, just call myDate.ToString(); you can optionally specify a format-string or predefined culture settings to get the right format (e.g. myDate.ToString(&quot;yyyy-MM-dd&quot;); or myDate.ToString(CultureInfo.CurrentCulture); )</p>
<p>&nbsp;</p>
<p>In .NET, every class inherits Object's .ToString() method, by default this method simply returns some basic information gained from Reflection, but some types (such as DateTime) override the behaviour. There is also the System.Convert class, but I find myself
 rarely using it (since it's nothing you can't do with the existing .TryParse / .Parse / .ToString methods.</p>
</div></blockquote>
<p><em>I'm no good at this, this is my code.</em></p>
<p><font face="Consolas" size="2"><font face="Consolas" size="2">there is an error on the line, [string mydate.....&nbsp;]and the next one ????????</font></font></p>
<p>&nbsp;</p>
<p><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">int</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2"> thedate =
</font></font><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">this</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2">.dateTimePicker1.Value.Day
 &amp; </font></font><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">this</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2">.dateTimePicker1.Value.Month
 &amp; </font></font><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">this</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2">.dateTimePicker1.Value.Year;</font></font></p>
<p><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">string</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2"> mydate = thedate.ToString;</font></font></p>
<p><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">this</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2">.richTextBox1.SaveFile(mydate);</font></font></p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/b752a2b7ec4b454dbf649deb000b2446#b752a2b7ec4b454dbf649deb000b2446</link>
		<pubDate>Sat, 26 Dec 2009 17:40:56 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/b752a2b7ec4b454dbf649deb000b2446#b752a2b7ec4b454dbf649deb000b2446</guid>
		<dc:creator>peoples</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/peoples/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">W3bbo said:</div><div class="quoteText">
<p>An &quot;int&quot; date?</p>
<p>&nbsp;</p>
<p>If you've got a DateTime instance, just call myDate.ToString(); you can optionally specify a format-string or predefined culture settings to get the right format (e.g. myDate.ToString(&quot;yyyy-MM-dd&quot;); or myDate.ToString(CultureInfo.CurrentCulture); )</p>
<p>&nbsp;</p>
<p>In .NET, every class inherits Object's .ToString() method, by default this method simply returns some basic information gained from Reflection, but some types (such as DateTime) override the behaviour. There is also the System.Convert class, but I find myself
 rarely using it (since it's nothing you can't do with the existing .TryParse / .Parse / .ToString methods.</p>
</div></blockquote>
<p>I got it you need () at the end of tostring !</p>
<p>&nbsp;</p>
<p>C# is new to me. Why does it not do the () in the dot completion system ?</p>
<p>&nbsp;</p>
<p>I got another question... In VB I use On Error Resume Next for errors, I need to write files and at times a file does not exist so i use the Error Handling to keep the code running. But I don't know how to do this in C# ???</p>
<p>&nbsp;</p>
<p>Thanks for help.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/38438398c84c4d6085e99deb000b2474#38438398c84c4d6085e99deb000b2474</link>
		<pubDate>Sat, 26 Dec 2009 18:00:35 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/38438398c84c4d6085e99deb000b2474#38438398c84c4d6085e99deb000b2474</guid>
		<dc:creator>peoples</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/peoples/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p>Dot notation is for member access.. the parenthesis denote method invocation.. without them it would be property/field access.</p>
<p>&nbsp;</p>
<p>The point being, ToString isn't a property of an object.. it is a method.. a method that says, give me a string representation of this object.</p>
<p>&nbsp;</p>
<p>(skipping your above code which I'm sure someone else will comment on).</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/9505e7efae88460698f99deb000b249f#9505e7efae88460698f99deb000b249f</link>
		<pubDate>Sat, 26 Dec 2009 18:30:55 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/9505e7efae88460698f99deb000b249f#9505e7efae88460698f99deb000b249f</guid>
		<dc:creator>stevo_</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/stevo_/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">W3bbo said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">figuerres said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>If its a date or time value stored in an integer representation of something like ticks or miliseconds then it's trivial, just multiply and cast to long to get ticks, then use DateTime's ticks constructor.</p>
<p>&nbsp;</p>
<p>If it's something like 25122009 then the OP has my sympathy, how does something like that happen?</p>
<p>&nbsp;</p>
<p>Well, if it is like 25122009 then convert it to a digit array (might as well just convert to a string) then extract the bits you need, then convert to int or datetime:</p>
<p>&nbsp;</p>
<p>String input = 25122009.ToString();</p>
<p>String dayStr = input.Substring(0,2);</p>
<p>String monStr = input.Substring(2,2);</p>
<p>String yerStr = input.Substring(4,4);</p>
<p>&nbsp;</p>
<p>DateTime date = new DateTime( int.Parse( dayStr ), int.Parse(monStr), int.Parse(yerStr) );</p>
</div></blockquote>
<p>Converting to string, substringing and parsing to integers is not really nice. And the DateTime-constructor you use is used wrongly: the first argument is the year and not the day.</p>
<p>Long live integer division and modulo:</p>
<p></p>
<pre class="brush: csharp">int d = 25122009;
DateTime date =
  new DateTime(
    d / 1000000,
    (d / 10000) % 100,
    d % 10000);</pre>
<p></p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/a3f8c218bcb14cfebb489deb000b24d2#a3f8c218bcb14cfebb489deb000b24d2</link>
		<pubDate>Sat, 26 Dec 2009 18:32:42 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/a3f8c218bcb14cfebb489deb000b24d2#a3f8c218bcb14cfebb489deb000b24d2</guid>
		<dc:creator>Tommy Carlier</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/TommyCarlier/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">TommyCarlier said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">W3bbo said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Converting to string, substringing and parsing to integers is not really nice. And the DateTime-constructor you use is used wrongly: the first argument is the year and not the day.</p>
<p>Long live integer division and modulo:</p>
<p></p>
<pre class="brush: csharp">int d = 25122009;
DateTime date =
  new DateTime(
    d / 1000000,
    (d / 10000) % 100,
    d % 10000);</pre>
<p></p>
</div></blockquote>
<p>Why can the first argument not be the day ?</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/bcd2c1026609454198739deb000b24ff#bcd2c1026609454198739deb000b24ff</link>
		<pubDate>Sat, 26 Dec 2009 19:00:03 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/bcd2c1026609454198739deb000b24ff#bcd2c1026609454198739deb000b24ff</guid>
		<dc:creator>peoples</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/peoples/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">peoples said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">TommyCarlier said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Why can the first argument not be the day ?</p>
</div></blockquote>
<p>... err because thats the way the constructor is defined? since the parameters aren't named, the order is very important.. how would the callee code know your intent when the intent is in your mind.</p>
<p>&nbsp;</p>
<p><a href="http://msdn.microsoft.com/en-us/library/xcfzdy4x.aspx">http&#58;&#47;&#47;msdn.microsoft.com&#47;en-us&#47;library&#47;xcfzdy4x.aspx</a></p>
<p>&nbsp;</p>
<p>Also, you stated a few times that c# is confusing vs vb, but these concepts (parenthesis, dot notation and param order) are absolutely fundamentals of many languages, especially the most popular ones... (even vb which you claim to know well)</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/c782e1aa037246589e099deb000b252c#c782e1aa037246589e099deb000b252c</link>
		<pubDate>Sat, 26 Dec 2009 19:45:53 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/c782e1aa037246589e099deb000b252c#c782e1aa037246589e099deb000b252c</guid>
		<dc:creator>stevo_</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/stevo_/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">peoples said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">W3bbo said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p><em>I'm no good at this, this is my code.</em></p>
<p><font face="Consolas" size="2"><font face="Consolas" size="2">there is an error on the line, [string mydate.....&nbsp;]and the next one ????????</font></font></p>
<p>&nbsp;</p>
<p><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">int</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2"> thedate =
</font></font><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">this</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2">.dateTimePicker1.Value.Day
 &amp; </font></font><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">this</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2">.dateTimePicker1.Value.Month
 &amp; </font></font><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">this</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2">.dateTimePicker1.Value.Year;</font></font></p>
<p><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">string</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2"> mydate = thedate.ToString;</font></font></p>
<p><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">this</font></font></font><font face="Consolas" size="2"><font face="Consolas" size="2">.richTextBox1.SaveFile(mydate);</font></font></p>
</div></blockquote>
<p>Your code won't work. In C# the '&amp;' operator is bitwise AND, so your code is doing the bitwise AND of the integer representations of day, month, and year, which is meaningless.</p>
<p>&nbsp;</p>
<p>Just do this:</p>
<p>&nbsp;</p>
<p>DateTime myDate = myDateTimePicker.Value;</p>
<p>String dateAsAString = myDate.ToString();</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/8980aaebe47742fab6df9deb000b255e#8980aaebe47742fab6df9deb000b255e</link>
		<pubDate>Sat, 26 Dec 2009 20:27:22 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/8980aaebe47742fab6df9deb000b255e#8980aaebe47742fab6df9deb000b255e</guid>
		<dc:creator>W3bbo</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/W3bbo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">TommyCarlier said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">W3bbo said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Converting to string, substringing and parsing to integers is not really nice. And the DateTime-constructor you use is used wrongly: the first argument is the year and not the day.</p>
<p>Long live integer division and modulo:</p>
<p></p>
<pre class="brush: csharp">int d = 25122009;
DateTime date =
  new DateTime(
    d / 1000000,
    (d / 10000) % 100,
    d % 10000);</pre>
<p></p>
</div></blockquote>
<p>Indeed, string conversion <em>is</em> hackish, but it has the benefit of being human-readable without needing to think too much about base-10 division.</p>
<p>&nbsp;</p>
<p>As for why I got the parameters wrong: I was getting it right in principle, I wasn't intending for my code to be taken verbatim (and if they did, it's a good exercise in why it's a good idea not to, so I can argue I got it wrong
<em>intentionally</em> <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-2.gif' alt='Big Smile' /> ).</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/4adf1b702b7f4fafa4769deb000b258b#4adf1b702b7f4fafa4769deb000b258b</link>
		<pubDate>Sat, 26 Dec 2009 20:29:07 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/4adf1b702b7f4fafa4769deb000b258b#4adf1b702b7f4fafa4769deb000b258b</guid>
		<dc:creator>W3bbo</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/W3bbo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">peoples said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">W3bbo said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>I got it you need () at the end of tostring !</p>
<p>&nbsp;</p>
<p>C# is new to me. Why does it not do the () in the dot completion system ?</p>
<p>&nbsp;</p>
<p>I got another question... In VB I use On Error Resume Next for errors, I need to write files and at times a file does not exist so i use the Error Handling to keep the code running. But I don't know how to do this in C# ???</p>
<p>&nbsp;</p>
<p>Thanks for help.</p>
</div></blockquote>
<p>For error handling, you're meant to use Try/Catch and Exceptions; The &quot;On Error Do Something&quot; in VB.NET is meant as a crutch for backwards compatibility with VB6 (i.e.
<em>never</em> use it in new projects).</p>
<p>&nbsp;</p>
<p>To see if a file exists or not:</p>
<p>&nbsp;</p>
<p>try {</p>
<p>&nbsp;&nbsp;&nbsp; FileStream fs = new FileStream(&quot;path to file&quot;);</p>
<p>} catch(FileNotFoundException fex) {</p>
<p>}</p>
<p>&nbsp;</p>
<p>...of course, you should never use exceptions for normal program flow, it's much better to test first:</p>
<p>&nbsp;</p>
<p>try {</p>
<p>&nbsp;&nbsp;&nbsp; if( File.Exists(&quot;path to file&quot;) ) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // do file operation here</p>
<p>&nbsp;&nbsp;&nbsp; } else {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // show error message to user</p>
<p>&nbsp;&nbsp;&nbsp; }</p>
<p>} catch(IOException ex) {</p>
<p>}</p>
<p>&nbsp;</p>
<p>And as you're using C#, you might as well make use of the using() {} block to ensure your program doesn't shít itself if something bad happens in the file IO ops.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/1781f0adb15e45b48c9f9deb000b25bb#1781f0adb15e45b48c9f9deb000b25bb</link>
		<pubDate>Sat, 26 Dec 2009 20:33:02 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/1781f0adb15e45b48c9f9deb000b25bb#1781f0adb15e45b48c9f9deb000b25bb</guid>
		<dc:creator>W3bbo</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/W3bbo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">W3bbo said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">peoples said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>For error handling, you're meant to use Try/Catch and Exceptions; The &quot;On Error Do Something&quot; in VB.NET is meant as a crutch for backwards compatibility with VB6 (i.e.
<em>never</em> use it in new projects).</p>
<p>&nbsp;</p>
<p>To see if a file exists or not:</p>
<p>&nbsp;</p>
<p>try {</p>
<p>&nbsp;&nbsp;&nbsp; FileStream fs = new FileStream(&quot;path to file&quot;);</p>
<p>} catch(FileNotFoundException fex) {</p>
<p>}</p>
<p>&nbsp;</p>
<p>...of course, you should never use exceptions for normal program flow, it's much better to test first:</p>
<p>&nbsp;</p>
<p>try {</p>
<p>&nbsp;&nbsp;&nbsp; if( File.Exists(&quot;path to file&quot;) ) {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // do file operation here</p>
<p>&nbsp;&nbsp;&nbsp; } else {</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // show error message to user</p>
<p>&nbsp;&nbsp;&nbsp; }</p>
<p>} catch(IOException ex) {</p>
<p>}</p>
<p>&nbsp;</p>
<p>And as you're using C#, you might as well make use of the using() {} block to ensure your program doesn't shít itself if something bad happens in the file IO ops.</p>
</div></blockquote>
<p>Thanks</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/cacea763388a49b0ab2d9deb000b25ea#cacea763388a49b0ab2d9deb000b25ea</link>
		<pubDate>Sat, 26 Dec 2009 21:18:53 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/cacea763388a49b0ab2d9deb000b25ea#cacea763388a49b0ab2d9deb000b25ea</guid>
		<dc:creator>peoples</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/peoples/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">peoples said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">W3bbo said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Thanks</p>
</div></blockquote>
<p>What does &quot;master of baiters&quot; mean <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /></p>
<p>&nbsp;</p>
<p>&nbsp;</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/fbd818843eb04530a1ad9deb000b2614#fbd818843eb04530a1ad9deb000b2614</link>
		<pubDate>Sun, 27 Dec 2009 13:26:31 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/fbd818843eb04530a1ad9deb000b2614#fbd818843eb04530a1ad9deb000b2614</guid>
		<dc:creator>peoples</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/peoples/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p>I think you'd benefit by a good book on C#.</p>
<p>&nbsp;</p>
<p>As for your code, the Value property of the DateTimePicker is already a DateTime type (similar to VB's Date type). Just call ToString() on the Value property and you'll get the default string representation of the date.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/f0ca656733f549468dff9deb000b263f#f0ca656733f549468dff9deb000b263f</link>
		<pubDate>Mon, 28 Dec 2009 14:12:24 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/f0ca656733f549468dff9deb000b263f#f0ca656733f549468dff9deb000b263f</guid>
		<dc:creator>Scott</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/spivonious/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">spivonious said:</div><div class="quoteText">
<p>I think you'd benefit by a good book on C#.</p>
<p>&nbsp;</p>
<p>As for your code, the Value property of the DateTimePicker is already a DateTime type (similar to VB's Date type). Just call ToString() on the Value property and you'll get the default string representation of the date.</p>
</div></blockquote>
<p>Can you recommend a good book for C# ?</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/09cec534fb494e8d97d49deb000b266b#09cec534fb494e8d97d49deb000b266b</link>
		<pubDate>Mon, 28 Dec 2009 19:59:58 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/09cec534fb494e8d97d49deb000b266b#09cec534fb494e8d97d49deb000b266b</guid>
		<dc:creator>peoples</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/peoples/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">peoples said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">spivonious said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Can you recommend a good book for C# ?</p>
</div></blockquote>
<p>Just one more question, I think if you call the datetime value you get a format like 11/12/2009, is it just a case of parseing out the &quot;/&quot; to make up the file name I want to use it as ?</p>
<p>&nbsp;</p>
<p>Thanks</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/f8614ab03da6406db44f9deb000b2696#f8614ab03da6406db44f9deb000b2696</link>
		<pubDate>Mon, 28 Dec 2009 20:01:42 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/f8614ab03da6406db44f9deb000b2696#f8614ab03da6406db44f9deb000b2696</guid>
		<dc:creator>peoples</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/peoples/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">peoples said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">peoples said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Just one more question, I think if you call the datetime value you get a format like 11/12/2009, is it just a case of parseing out the &quot;/&quot; to make up the file name I want to use it as ?</p>
<p>&nbsp;</p>
<p>Thanks</p>
</div></blockquote>
<p>Its better to do something like</p>
<p>&nbsp;</p>
<p>string filename = string.format(&quot;d:\\logs\\{0}{1}{2}.log&quot;, myDate.Day, myDate.Month, myDate.Year);</p>
<p>&nbsp;</p>
<p>Date.ToString() looks different depending on the local of the user, so parsing out / wont work for instance for german versions of windows (&#43; its really ugly).</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/4ac10e4e5cdd4885b6499deb000b26de#4ac10e4e5cdd4885b6499deb000b26de</link>
		<pubDate>Mon, 28 Dec 2009 20:34:49 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/4ac10e4e5cdd4885b6499deb000b26de#4ac10e4e5cdd4885b6499deb000b26de</guid>
		<dc:creator>the_corona</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/the_corona/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">the_corona said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">peoples said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>Its better to do something like</p>
<p>&nbsp;</p>
<p>string filename = string.format(&quot;d:\\logs\\{0}{1}{2}.log&quot;, myDate.Day, myDate.Month, myDate.Year);</p>
<p>&nbsp;</p>
<p>Date.ToString() looks different depending on the local of the user, so parsing out / wont work for instance for german versions of windows (&#43; its really ugly).</p>
</div></blockquote>
<p>That's not necessary. If you want to be culture independent, just use the invariant culture:</p>
<p>&nbsp;</p>
<p></p>
<pre class="brush: text">string filename = string.Format(CultureInfo.InvariantCulture, @&quot;D:\logs\{0:ddMMyyyy}.log&quot;, myDate)</pre>
<p></p>
<p>&nbsp;</p>
<p>This would have the same general effect as your code, without having to do manual date formatting.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/47dff537a7e4428ea7879deb000b270b#47dff537a7e4428ea7879deb000b270b</link>
		<pubDate>Mon, 28 Dec 2009 21:11:59 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/47dff537a7e4428ea7879deb000b270b#47dff537a7e4428ea7879deb000b270b</guid>
		<dc:creator>Sven Groot</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Sven Groot/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Sven Groot said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">the_corona said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>That's not necessary. If you want to be culture independent, just use the invariant culture:</p>
<p>&nbsp;</p>
<p></p>
<pre class="brush: text">string filename = string.Format(CultureInfo.InvariantCulture, @&quot;D:\logs\{0:ddMMyyyy}.log&quot;, myDate)</pre>
<p></p>
<p>&nbsp;</p>
<p>This would have the same general effect as your code, without having to do manual date formatting.</p>
</div></blockquote>
<p>ah, yes thats interesting, though I've never seen this before. I have to wonder though why you need to specify culturinvariant in that example given you very specifically ask for ddMMyyyy ?</p>
<p>&nbsp;</p>
<p>But come to think of it, Date.ToString I think also has an overload to do the formating the way you want, so even something like myDate.ToString(&quot;ddMMYYYY&quot;) - (I'm not sure of the exact syntax) - could get you a culture invariant string.</p>
<p>&nbsp;</p>
<p>Thinking about this more. does the {0:xx} in string.format end up as a string parameter to the first argument's ToString(string format)
</p>
<p>overload? So it ends up like </p>
<p>string.format(&quot;{0:xx}&quot;, myDate) == string.format(&quot;{0}&quot;, myDate.ToString(&quot;xx&quot;));</p>
<p>Does this work in general or only with DateTime?</p>
<p>&nbsp;</p>
<p>&nbsp;</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/0d561fec33494043af959deb000b273a#0d561fec33494043af959deb000b273a</link>
		<pubDate>Mon, 28 Dec 2009 21:31:31 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/0d561fec33494043af959deb000b273a#0d561fec33494043af959deb000b273a</guid>
		<dc:creator>the_corona</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/the_corona/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">the_corona said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">Sven Groot said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>ah, yes thats interesting, though I've never seen this before. I have to wonder though why you need to specify culturinvariant in that example given you very specifically ask for ddMMyyyy ?</p>
<p>&nbsp;</p>
<p>But come to think of it, Date.ToString I think also has an overload to do the formating the way you want, so even something like myDate.ToString(&quot;ddMMYYYY&quot;) - (I'm not sure of the exact syntax) - could get you a culture invariant string.</p>
<p>&nbsp;</p>
<p>Thinking about this more. does the {0:xx} in string.format end up as a string parameter to the first argument's ToString(string format)
</p>
<p>overload? So it ends up like </p>
<p>string.format(&quot;{0:xx}&quot;, myDate) == string.format(&quot;{0}&quot;, myDate.ToString(&quot;xx&quot;));</p>
<p>Does this work in general or only with DateTime?</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div></blockquote>
<p>It works because the formatting system has an interface IFormattable which any type can implement, it specifies the type then must have a method ToString(string format, IFormatProvider formatProvider).</p>
<p>&nbsp;</p>
<p>The string 'format' would be the part after the colon in String.Format, and of course you can call it directly as in your example of myDate.ToString(&quot;ddMMYYYY&quot;) (which is actually an overload that doesn't require you to specify the format provider).</p>
<p>&nbsp;</p>
<p>The String.Format method works by scanning for the curly brace syntax, if it detects the colon then the following characters until the closing brace are considered the format, if the argument in question is IFormattable then it passes in the format with
 a format provider it either discovered itself or you provided in the Format call.</p>
<p>&nbsp;</p>
<p>If the type isn't formattable it simply calls ToString on it to get a string value.</p>
<p>&nbsp;</p>
<p>So if you want your type to have its own custom formatting like:</p>
<p>&nbsp;</p>
<p>string.Format(&quot;{0:omgbbq}&quot;, instanceofmytype).</p>
<p>&nbsp;</p>
<p>You simply need to implement IFormattable on your type and do the work to process what the format ('omgbbq' in this case) should mean.</p>
<p>&nbsp;</p>
<p>The format providers role is to allow 'outsiders' to specify their own formatter (ICustomFormatter) (albiet imo somewhat convolutedly).</p>
<p>&nbsp;</p>
<p>The concept when implementing is.. is a format provider was given, try and get a custom formatter from it, if you get one use that.. otherwise use your own built in formatting.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/6a77d942a4724a8bab1a9deb000b276d#6a77d942a4724a8bab1a9deb000b276d</link>
		<pubDate>Mon, 28 Dec 2009 23:39:30 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/6a77d942a4724a8bab1a9deb000b276d#6a77d942a4724a8bab1a9deb000b276d</guid>
		<dc:creator>stevo_</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/stevo_/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">stevo_ said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">the_corona said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>It works because the formatting system has an interface IFormattable which any type can implement, it specifies the type then must have a method ToString(string format, IFormatProvider formatProvider).</p>
<p>&nbsp;</p>
<p>The string 'format' would be the part after the colon in String.Format, and of course you can call it directly as in your example of myDate.ToString(&quot;ddMMYYYY&quot;) (which is actually an overload that doesn't require you to specify the format provider).</p>
<p>&nbsp;</p>
<p>The String.Format method works by scanning for the curly brace syntax, if it detects the colon then the following characters until the closing brace are considered the format, if the argument in question is IFormattable then it passes in the format with
 a format provider it either discovered itself or you provided in the Format call.</p>
<p>&nbsp;</p>
<p>If the type isn't formattable it simply calls ToString on it to get a string value.</p>
<p>&nbsp;</p>
<p>So if you want your type to have its own custom formatting like:</p>
<p>&nbsp;</p>
<p>string.Format(&quot;{0:omgbbq}&quot;, instanceofmytype).</p>
<p>&nbsp;</p>
<p>You simply need to implement IFormattable on your type and do the work to process what the format ('omgbbq' in this case) should mean.</p>
<p>&nbsp;</p>
<p>The format providers role is to allow 'outsiders' to specify their own formatter (ICustomFormatter) (albiet imo somewhat convolutedly).</p>
<p>&nbsp;</p>
<p>The concept when implementing is.. is a format provider was given, try and get a custom formatter from it, if you get one use that.. otherwise use your own built in formatting.</p>
</div></blockquote>
<p>Awesome, thnx for the clear explanation. Learned something valuable today!</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/9d4b96985cdf43f4ab179deb000b279c#9d4b96985cdf43f4ab179deb000b279c</link>
		<pubDate>Tue, 29 Dec 2009 11:44:32 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/9d4b96985cdf43f4ab179deb000b279c#9d4b96985cdf43f4ab179deb000b279c</guid>
		<dc:creator>the_corona</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/the_corona/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">the_corona said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">Sven Groot said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>ah, yes thats interesting, though I've never seen this before. I have to wonder though why you need to specify culturinvariant in that example given you very specifically ask for ddMMyyyy ?</p>
<p>&nbsp;</p>
<p>But come to think of it, Date.ToString I think also has an overload to do the formating the way you want, so even something like myDate.ToString(&quot;ddMMYYYY&quot;) - (I'm not sure of the exact syntax) - could get you a culture invariant string.</p>
<p>&nbsp;</p>
<p>Thinking about this more. does the {0:xx} in string.format end up as a string parameter to the first argument's ToString(string format)
</p>
<p>overload? So it ends up like </p>
<p>string.format(&quot;{0:xx}&quot;, myDate) == string.format(&quot;{0}&quot;, myDate.ToString(&quot;xx&quot;));</p>
<p>Does this work in general or only with DateTime?</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div></blockquote>
<p>You need to specify InvariantCulture because even with a simple format like that it might have unexpected results if you use the current culture. For instance, the culture might not even use the western calendar!</p>
<p>&nbsp;</p>
<p>For example, if I do this:</p>
<p></p>
<pre class="brush: text">CultureInfo culture = new CultureInfo(&quot;ja-JP&quot;);
// Japanese culture settings uses Western calendar by default; might not be true for all cultures though.
culture.DateTimeFormat.Calendar = new JapaneseCalendar();
Thread.CurrentThread.CurrentCulture = culture;

string result = myDate.ToString(&quot;ddMMyyyy&quot;);</pre>
<p></p>
<p>&nbsp;</p>
<p>In this case, I've changed the current culture to something that uses a different calendar. Now, if myDate is&nbsp;December 29th 2009,&nbsp;the string result will be &quot;291221&quot;. Why? Because on the Japanese calendar, the current year is Heisei 21.</p>
<p>&nbsp;</p>
<p>It's easily imaginable that on some system, somewhere, the default culture will be set to something that doesn't produce the correct result even with the format string &quot;ddMMyyyy&quot;. That's why you
<em>always</em> specify the InvariantCulture if you need a specific result, even if you think it doesn't matter.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/40b842f1335a4ba3b4fd9deb000b27ce#40b842f1335a4ba3b4fd9deb000b27ce</link>
		<pubDate>Tue, 29 Dec 2009 14:39:06 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/40b842f1335a4ba3b4fd9deb000b27ce#40b842f1335a4ba3b4fd9deb000b27ce</guid>
		<dc:creator>Sven Groot</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Sven Groot/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Sven Groot said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">the_corona said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>You need to specify InvariantCulture because even with a simple format like that it might have unexpected results if you use the current culture. For instance, the culture might not even use the western calendar!</p>
<p>&nbsp;</p>
<p>For example, if I do this:</p>
<p></p>
<pre class="brush: text">CultureInfo culture = new CultureInfo(&quot;ja-JP&quot;);
// Japanese culture settings uses Western calendar by default; might not be true for all cultures though.
culture.DateTimeFormat.Calendar = new JapaneseCalendar();
Thread.CurrentThread.CurrentCulture = culture;

string result = myDate.ToString(&quot;ddMMyyyy&quot;);</pre>
<p></p>
<p>&nbsp;</p>
<p>In this case, I've changed the current culture to something that uses a different calendar. Now, if myDate is&nbsp;December 29th 2009,&nbsp;the string result will be &quot;291221&quot;. Why? Because on the Japanese calendar, the current year is Heisei 21.</p>
<p>&nbsp;</p>
<p>It's easily imaginable that on some system, somewhere, the default culture will be set to something that doesn't produce the correct result even with the format string &quot;ddMMyyyy&quot;. That's why you
<em>always</em> specify the InvariantCulture if you need a specific result, even if you think it doesn't matter.</p>
</div></blockquote>
<p>It's a pity that .NET doesn't make a distinction between &quot;data strings&quot; and &quot;display strings&quot;. I mean, instead of ToString() you'd have ToDataString() which returns a culture-independent string of data, and ToDisplayString() which returns a culture-dependent
 string used for display purposes.</p>
<p>In my own code, I've created some static classes with extension methods to convert values (int, long, DateTime, ...) to data strings and back. You can then write code like this:</p>
<p></p>
<pre class="brush: csharp">DateTime d = DateTime.Today;
string s = d.ToDataString(); // s will be &quot;2009-12-29&quot;
d = s.ToDateTime();</pre>
<p></p>
<p>It also knows about nullable values, so you can use s.ToDateTimeOrNull() or convert nullable DateTime to data string.</p>
<p>You can find the code on <a href="http://tc.codeplex.com/">CodePlex</a> (in folder TC/src/TC.Core in the files ConvertXXX.cs).</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/dd46b8690bdd49f7bb469deb000b2800#dd46b8690bdd49f7bb469deb000b2800</link>
		<pubDate>Tue, 29 Dec 2009 14:50:05 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/dd46b8690bdd49f7bb469deb000b2800#dd46b8690bdd49f7bb469deb000b2800</guid>
		<dc:creator>Tommy Carlier</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/TommyCarlier/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">TommyCarlier said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">Sven Groot said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>It's a pity that .NET doesn't make a distinction between &quot;data strings&quot; and &quot;display strings&quot;. I mean, instead of ToString() you'd have ToDataString() which returns a culture-independent string of data, and ToDisplayString() which returns a culture-dependent
 string used for display purposes.</p>
<p>In my own code, I've created some static classes with extension methods to convert values (int, long, DateTime, ...) to data strings and back. You can then write code like this:</p>
<p></p>
<pre class="brush: csharp">DateTime d = DateTime.Today;
string s = d.ToDataString(); // s will be &quot;2009-12-29&quot;
d = s.ToDateTime();</pre>
<p></p>
<p>It also knows about nullable values, so you can use s.ToDateTimeOrNull() or convert nullable DateTime to data string.</p>
<p>You can find the code on <a href="http://tc.codeplex.com/">CodePlex</a> (in folder TC/src/TC.Core in the files ConvertXXX.cs).</p>
</div></blockquote>
<p>Because ToDataString is essentially the same thing as serialisation, and there are dedicated classes for that. I'm happy with the current simplistic design and I don't feel it needs to be refactored any. If a class has a meaningful culture-specific string
 representation then always use the IFormatProvider overload.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/d2202cb6fe174f3baad79deb000b282e#d2202cb6fe174f3baad79deb000b282e</link>
		<pubDate>Tue, 29 Dec 2009 14:53:54 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/d2202cb6fe174f3baad79deb000b282e#d2202cb6fe174f3baad79deb000b282e</guid>
		<dc:creator>W3bbo</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/W3bbo/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">TommyCarlier said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">Sven Groot said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>It's a pity that .NET doesn't make a distinction between &quot;data strings&quot; and &quot;display strings&quot;. I mean, instead of ToString() you'd have ToDataString() which returns a culture-independent string of data, and ToDisplayString() which returns a culture-dependent
 string used for display purposes.</p>
<p>In my own code, I've created some static classes with extension methods to convert values (int, long, DateTime, ...) to data strings and back. You can then write code like this:</p>
<p></p>
<pre class="brush: csharp">DateTime d = DateTime.Today;
string s = d.ToDataString(); // s will be &quot;2009-12-29&quot;
d = s.ToDateTime();</pre>
<p></p>
<p>It also knows about nullable values, so you can use s.ToDateTimeOrNull() or convert nullable DateTime to data string.</p>
<p>You can find the code on <a href="http://tc.codeplex.com/">CodePlex</a> (in folder TC/src/TC.Core in the files ConvertXXX.cs).</p>
</div></blockquote>
<p>Tommy it can get even worse than that.....</p>
<p>&nbsp;</p>
<p>if you make a web service that passes a datetime to a client (or client to server) if the client and server are in different timezones the date and time will not be right!</p>
<p>the soap dattime is just a date and time string with no timezone info.</p>
<p>and .net make the date a &quot;local&quot; timezone based date.</p>
<p>&nbsp;</p>
<p>in some stuff i do i have to pass the datetime as a string to avoid some issues with that.</p>
<p>i also have an app that has to convert date and time across timezones and has to show 2 date-time values for a given event.</p>
<p>one is always eastern US time and the other can be anywhere... when i first set that up i had folks telling me it was wrong cuse they did not understand the nutty rules that some locales have for when to add or subtract time from UTC / zero.</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/d33396e111de485eb4979deb000b2861#d33396e111de485eb4979deb000b2861</link>
		<pubDate>Tue, 29 Dec 2009 15:07:24 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/d33396e111de485eb4979deb000b2861#d33396e111de485eb4979deb000b2861</guid>
		<dc:creator>figuerres</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/figuerres/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - C# Sting converstion</title>
		<description><![CDATA[<p><blockquote><div class="quoteUser">Sven Groot said:</div><div class="quoteText">
<blockquote>
<div class="quoteUser">the_corona said:</div>
<div class="quoteText">*snip*</div>
</blockquote>
<p>You need to specify InvariantCulture because even with a simple format like that it might have unexpected results if you use the current culture. For instance, the culture might not even use the western calendar!</p>
<p>&nbsp;</p>
<p>For example, if I do this:</p>
<p></p>
<pre class="brush: text">CultureInfo culture = new CultureInfo(&quot;ja-JP&quot;);
// Japanese culture settings uses Western calendar by default; might not be true for all cultures though.
culture.DateTimeFormat.Calendar = new JapaneseCalendar();
Thread.CurrentThread.CurrentCulture = culture;

string result = myDate.ToString(&quot;ddMMyyyy&quot;);</pre>
<p></p>
<p>&nbsp;</p>
<p>In this case, I've changed the current culture to something that uses a different calendar. Now, if myDate is&nbsp;December 29th 2009,&nbsp;the string result will be &quot;291221&quot;. Why? Because on the Japanese calendar, the current year is Heisei 21.</p>
<p>&nbsp;</p>
<p>It's easily imaginable that on some system, somewhere, the default culture will be set to something that doesn't produce the correct result even with the format string &quot;ddMMyyyy&quot;. That's why you
<em>always</em> specify the InvariantCulture if you need a specific result, even if you think it doesn't matter.</p>
</div></blockquote>
<p>Ah, yes. AFAIK the thai system by default uses the buddist year, so 2009 is 2552.
</p>
<p>&nbsp;</p>
<p>Quite confusing in fact when you're there <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /></p>
<p>&nbsp;</p>
<p>Thread.CurrentThread.CurrentCulture = new CultureInfo(&quot;th-th&quot;);<br>
Console.WriteLine(DateTime.Now);</p>
<p>&nbsp;</p>
<p>Result: 29/12/2552 16:37:51</p></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/d611486e48ed4ddf81ff9deb000b2890#d611486e48ed4ddf81ff9deb000b2890</link>
		<pubDate>Tue, 29 Dec 2009 15:18:55 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/516010-C-Sting-converstion/d611486e48ed4ddf81ff9deb000b2890#d611486e48ed4ddf81ff9deb000b2890</guid>
		<dc:creator>the_corona</dc:creator>
		<slash:comments>28</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/the_corona/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>