How to convert the date received from the database only for displaying d / mm / yyyy?

I have this value 21/10/1999inserted manually into the SQL database and when I get it like this:

txtDOB.Text = readPatient["pDOB"].ToString();

It displays everything along with time 12:00:00 AM. My data type is for a date column date, not datetime. So why does it display time?

+4
source share
7 answers
((DateTime)readPatient["pDOB"]).ToString("d");

For a list of supported formats, see: http://msdn.microsoft.com/es-es/library/zdtaw1bw(v=vs.110).aspx

+8
source

You may try

txtDOB.Text = Convert.ToDateTime(readPatient["pDOB"]).ToString("dd/MM/yyyy", CultureInfo.InvariantCulture);

Edit: thanks to comments I saw that I forgot to throw in datetime

+4
source

, , . :

?

SQL .NET. .NET SQL "" DateTime, . SQL .NET, . : SQL Server

+1

txtDOB.Text=Convert.toDateTime(readPatient["pDOB"]).ToString("d/MM/yyyy");
0

ToString , ,

:

TextBox1.Text =Convert.toDateTime(readPatient["pDOB"]).ToString("d/MM/yyyy");
0

datetimepicker, . datetimepicker. ( ), ( ) yy-MM-dd,

0
DateTime dt = Convert.ToDateTime(sqdr["invdate"].ToString());
dt.Date;  //To get the date only
0
source

Source: https://habr.com/ru/post/1524661/


All Articles