String format

string value1 = “Dot Net Perls”;

int value2 = 10000;

DateTime value3 = new DateTime(2007, 11, 1);

string result = string.Format(“{0}:{1:0.0}-{2:yyyy}”, value1, value2, value3);

//Output: DotNetPerls: 10000.0-2007

Anuncios

DateTime from C# to SQL

string tempDate;

tempDate = Convert.ToDateTime(dataGridView1.CurrentRow.Cells[1].Value.ToString()).ToString(“yyyy-MM-dd HH:mm:ss”);

query = “UPDATE…WHERE CheckDate = CONVERT(datetime, ‘” + tempDate + “‘, 121)”;

Get dateTimePicker value with certain format

dateTimePicker1.Value.ToString(“yyyyMMdd”);