Hi,
I retrieves the date field as '2022-11-11T00:00:00+05:30', when fetches from Sql table, but need only date as '2022-11-11'
Can you plz suggest how to get the same using the format with C# code or sql.
Thanks
Sathish
Hi,
I retrieves the date field as '2022-11-11T00:00:00+05:30', when fetches from Sql table, but need only date as '2022-11-11'
Can you plz suggest how to get the same using the format with C# code or sql.
Thanks
Sathish
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal JoshiRank #377 · 6.7K reputationPosted Nov 22, 2022, 6:07 AM EST
Hello Sathish,
You can try the below way to get only Date from the DateTime.
string sqlDate = "2022-11-11T00:00:00+05:30"; DateTime resultDate; string displayDate = string.Empty; if (DateTime.TryParse(sqlDate, out resultDate)) displayDate = resultDate.ToString("yyyy-MM-dd"); Console.WriteLine("Only Date: " + displayDate);Thanks
Naresh BeniwalRank #365 · 6.8K reputationPosted Nov 22, 2022, 5:27 AM EST
https://stackoverflow.com/questions/3025361/c-sharp-datetime-to-yyyymmddhhmmss-format
Rajanikant HawaldarRank #110 · 20.3K reputationPosted Nov 22, 2022, 5:38 AM EST
https://www.c-sharpcorner.com/blogs/date-and-time-format-in-c-sharp-programming1
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 22, 2022, 6:40 AM EST
use this one in sql query CONVERT(char(10), orderedDate ,126),
select top 10 CONVERT(char(10), orderedDate ,126) as formatedDate from ci_orders