it is in yyyy/MM/dd format.
I'm retrieving that date into my UI.
but it is showing this format dd/MM/yyyy
the result is (Conversion failed when converting date and/or time from character string).
how can i change the date format to yyyy/MM/dd.
the coming output = " 27-05-2014 00:18:22 "
My required output = " 2014-05-27 00:18:22"
Thanks In Advance!

Khan Abrar AhmedRank #778 · 3K reputationPosted May 26, 2014, 10:12 PM EDT
C#
Convert.ToDateTime(dateTime).ToString("yyyy-MM-dd");
or in sql server script
SELECT REPLACE(CONVERT(VARCHAR(24),GETDATE(),102),'.','/')
Anupam SinghRank #643 · 3.7K reputationPosted May 26, 2014, 10:29 PM EDT
You can format date in C# .
You can find the list of formats :
http://www.csharp-examples.net/string-format-datetime/
Hope it helps
vladimir omni3 reputationPosted May 26, 2014, 11:30 PM EDT
Khan Abrar AhmedRank #778 · 3K reputationPosted May 26, 2014, 11:45 PM EDT
can you please let us know where exactly you want the out in sql db or in c#
Khan Abrar AhmedRank #778 · 3K reputationPosted May 26, 2014, 11:48 PM EDT
you can try this also
SELECT CONVERT(VARCHAR(24),GETDATE(),120)
or please refer the link
http://www.sqlusa.com/bestpractices/datetimeconversion/
Jignesh TrivediRank #16 · 50.3K reputationPosted May 27, 2014, 12:25 AM EDT
hi,
Are you pass your UI date to query? how?
suppose you are writing query and execute it using command or adaper than try following...
using (SqlCommand command = new SqlCommand(
"SELECT * FROM table1 WHERE Date = @Date", connection))
{
DateTime dt;
DateTime dt;
DateTime.TryParseExact("your date", "dd/MM/yyyy", new System.Globalization.CultureInfo("en-US"), System.Globalization.DateTimeStyles.None, out dt);
//
// Add new SqlParameter to the command.
//
command.Parameters.Add(new SqlParameter("Date", dt));
//
// Read in the SELECT results.
//
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
}
}
hope this will help you.