-3

Here is my date time format displayed

Dr["DATE"] =========> Jun 27 2014 9:06PM

I want it to display like this one =========> 27.06.2014

Here is my code:

ltrlNotlar.Text = Dr["DATE"].ToString()

How to change first format to the second one?

Thankss

allence
  • 569
  • 1
  • 5
  • 12
  • 1
    What is `Dr`? A DataRow? A DataReader? – gunr2171 Jul 03 '14 at 19:10
  • 5
    [Standard Date and Time Format Strings on MSDN](http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx) and [Custom Date and Time Format Strings](http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx) will undoubtedly be useful to you. – mason Jul 03 '14 at 19:11
  • 2
    This has been asked [so](http://stackoverflow.com/questions/5162243/datetime-format) [many](http://stackoverflow.com/questions/3025361/c-sharp-datetime-to-yyyymmddhhmmss-format) [times](http://stackoverflow.com/questions/4900208/format-datetime-in-c-sharp) before in other ways – Patrick Jul 03 '14 at 19:20

3 Answers3

3

use DateTime to do the conversion for you

var dt = DateTime.Parse(Dr["DATE"].ToString());

ltrlNotlar.Text = dt.ToString("dd.MM.yyyy");
Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
2

If Dr is a DataRow, you can this

ltrlNotlar.Text = dr.Field<DateTime>("DATE").ToString("dd.MM.yyyy");

I like using .Field because it does the casting for you. However this only works if the sql column is a Date or DateTime (or possibly DateTimeOffset). If you are storing your date as a string in the database, this won't work.

If the sql column DATE is nullable, make sure to change the generic argument to DateTime?.

gunr2171
  • 16,104
  • 25
  • 61
  • 88
0

you could also use something like this:

Convert.ToDateTime(SomeDateTime).ToString("MM.dd.yyyy");
D4RKCIDE
  • 3,439
  • 1
  • 18
  • 34