Is there any way for getting date alone from UniversalSortableDateTimePattern using this in Export to Excel function. The Excel doesn't accepts the date format..
I need to display as yyyy-MM-dd.
Any suggestions ll be helpful ?
My code as
dtASalesDrivers.Columns.Add(new System.Data.DataColumn("Start Date", typeof(String)));
DateTime dt = Convert.ToDateTime(txtATrendStartDate.Text);
drASalesDrivers[2] = string.Format("{0:yyyy-MM-dd}", dt);
dtASalesDrivers.Rows.Add(drASalesDrivers);
Edit :
DateTime dt = Convert.ToDateTime(txtATrendStartDate.Text);
drASalesDrivers[2] = string.Format("{0:u}", dt);
This displays both date and time. Is there any way for displaying only date ???
here is my code, I realize it by following code:
I think that is to do with your computers settings.
If you open up a new instance of Excel and type
2012-07-24
and navigate away from the cell, it will instantly change to24/07/2012
, it is more your computers regional settings than anything to do with your code.You can however format the cell to
yyyy-mm-dd;@
so you may need to do this programmatically and not change anything else, I think that this may work:But I haven't tested it
I was doing some messing around and some example code is below:
Also,
string.Format("{0:u}", dt);
will indeed return a date and a time,dt.ToString("yyyy-MM-dd");
will return your date.The alrernative is to change your
Short date
setting on your computer to yyy-MM-dd like so:This will make your date appear how you want by default on Excel on your computer, but it will look differently on different computers.