Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# convert datetime to custom format

Tags:

c#

sql

I'm querying a datetime (dd/mm/YYYY hh:mm:ss) value from a database and inserting it in a list like this:

ord.invoiceDate = dt.Rows[i]["invoicedate"].ToString();

How can I convert this string to a custom format like dd-MM-YYYY ? I don't want the hours minutes and seconds.

like image 609
n3bi0s Avatar asked Feb 05 '26 08:02

n3bi0s


1 Answers

Try this

ord.invoiceDate = ((DateTime)dt.Rows[i]["invoicedate"]).ToString("dd-MM-yyyy");
like image 133
Serge Avatar answered Feb 06 '26 22:02

Serge