ASP.NET C# convert date format to yyyy-MM-dd HH:mm:ss

http://stackoverflow.com/questions/2210286/how-to-convert-datetime-to-a-particular-format

For me its wirking with following:

fielddata4 = ’26/05/2011′
DateTime dt = DateTime.Parse(fielddata4);
string date = Change_to_rangevalidator(dt);

public static string Change_to_rangevalidator(DateTime dt)
{
//string strTest = stringTest();
string format = “yyyy-MM-dd HH:mm:ss”;
string date = dt.ToString(format, DateTimeFormatInfo.InvariantInfo);
return date;
}

in vb:

Dim tdate As String
tdate = DateTime.Now.ToString(“MMddyy”)    ****dd and yy need to be in small. Not caps

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s