开发者

Convert date issue in c#

I h开发者_如何学Pythonave dateformat issue where I need to convert the date from DB to different formats according to the login

Like I have 3 different format

DD/MM/YY,MM/DD/YY,DD/MMM/YY I tried to convert using the following methods but no luck.

DateTime.TryParseExact(drtemp["StartDate"].ToString(),dateFormat,null,
   System.Globalization.DateTimeStyles.None,out startDate);
orderDate =DateTime.ParseExact(drtemp["StartDate"].ToString(), dateFormat, null);

Any help is highly apprenticed Thanks, Magz


You can do:

string formattedDate = ((DateTime)drtemp["StartDate"]).ToString(dateFormat);

See MSDN DateTime.ToString reference


Or You could do this:

String.Format(dateFormat, (DateTime)drtemp["StartDate"])


Try

string date = DateTime.Now.ToString("dd/MM/yy");
string date1 = DateTime.Now.ToString("MM/dd/yy");
string date2 = DateTime.Now.ToString("dd/MMM/yy");

In your case you could do

string formattedDate = drtemp["StartDate"].ToString("dd/MM/yy");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜