Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从DB表中获取没有时间的日期_C#_Mysql - Fatal编程技术网

C# 从DB表中获取没有时间的日期

C# 从DB表中获取没有时间的日期,c#,mysql,C#,Mysql,因此,我试图从数据库表中获取日期,并将其显示在标签文本中。 我正在使用以下代码: this.label011.Text = myReader.GetString("Registration_Date"); 它可以工作,但当它显示数据时,显示为2017年2月10日12:00AM。 我只想看日期,不想看时间。表中存储的数据是“2017年2月10日”,为什么会在12:00发布?数据存储为日期时间。您需要对其进行格式化才能正确显示 ((DateTime)myReader["Registration_D

因此,我试图从数据库表中获取日期,并将其显示在标签文本中。 我正在使用以下代码:

this.label011.Text = myReader.GetString("Registration_Date");
它可以工作,但当它显示数据时,显示为2017年2月10日12:00AM。
我只想看日期,不想看时间。表中存储的数据是“2017年2月10日”,为什么会在12:00发布?数据存储为
日期时间
。您需要对其进行格式化才能正确显示

((DateTime)myReader["Registration_Date"]).ToShortDateString();


为什么要将其作为字符串而不是日期时间?如果您将其作为
日期时间
,则可以执行
.ToString(“M/d/yyyy”)
myReader.GetDateTime("Registration_Date").ToShortDateString();