Monday, March 17, 2008

Formatting DateTime Strings on Databinding in C#

Ok, I got confused on how to format datatime strings on a simple databind on a column in say a GridView in .Net 3.5 (maybe 2.0 as well). So I did some research. The below string will get you started.

Text='<%# ((DateTime)Eval("mydate")).ToString("d") %>'

For format codes, check out here-

Here is another code snippet that might help as well.

DateTime.Now.ToString ( "yyyy/MM/dd",
CultureInfo.InvariantCulture );

1 comment:

Sergio said...