How to change Datetime Format

Posted by Oswaldlily under ASP.NET on 5/18/2012 | Points: 10 | Views : 4675 | Status : [Member] | Replies : 4
Datetime d;
d=Convert.ToDateTime(txtCalendar.Text);

so "d" carries date in this format "yyyy/MM/dd"

while using Convert.ToDateTime i need like "yyyy-MM-dd"




Responses

Posted by: Kkdubey on: 5/18/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
i think ,you should try this method.........
DateTime date = Convert.ToDateTime("31/01/2000");
Console.WriteLine(date);
String format = "yyyy-MM-dd";
String dateStr = date.ToString(format);
Console.WriteLine(dateStr);

Output:
2000-01-31

Regards,
Krishna

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sekar.C on: 5/19/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
try this code
DateTime mydate = Convert.ToDateTime(System.DateTime.Now.ToString());

TextBox1.Text = mydate.ToString("yyyy-MM-dd hh:mm:ss");


Regards
Sekar.c

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 5/21/2012 [Member] Starter | Points: 25

Up
0
Down
DateTime.Now.ToString("yyyy/MM/dd")

Try this.

Ajay
ajaypatelfromsanthal.blogspot.in

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 6/11/2012 [Member] Bronze | Points: 25

Up
0
Down
http://www.dotnetperls.com/datetime-format

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response