如何消除Gridview
中Datefield
中的时间部分?因此,在我的数据库中,它没有时间部分,但是当在 ASP.net 中的 Gridview 中查看时,它会出现 Ex:我的数据在 DateField
中:
2016-05-01 12:00:00 AM
我要删除:
12:00:00 AM
因此该字段将显示:
2016-05-01
aspx:
<asp:GridView ID="GridView1" runat="server"
AllowSorting="True"
HorizontalAlign="Center" BackColor="White" BorderColor="#3366CC"
BorderStyle="None" BorderWidth="1px" CellPadding="4"
ViewStateMode="Enabled"
PageSize="20"
onselectedindexchanged="GridView1_SelectedIndexChanged1"
EnableSortingAndPagingCallbacks="True">
<PagerSettings FirstPageText="First" PreviousPageText="Previous"
NextPageText="Next" LastPageText="Last" Mode="NextPrevious" />
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
最佳答案
如果您确实想从字符串中执行此操作,可以使用substring_index
SELECT SUBSTRING_INDEX('2016-05-01 12:00:00 AM', ' ', 1);
示例
MariaDB [yourschema]> SELECT SUBSTRING_INDEX('2016-05-01 12:00:00 AM', ' ', 1);
+---------------------------------------------------+
| SUBSTRING_INDEX('2016-05-01 12:00:00 AM', ' ', 1) |
+---------------------------------------------------+
| 2016-05-01 |
+---------------------------------------------------+
1 row in set (0.00 sec)
MariaDB [yourschema]>
如果您从数据库中获取日期,则可以使用 DATE_FORMAT 对其进行格式化
SELECT DATE_FORMAT('2016-05-01 12:00:00 AM', '%Y-%m-%d');
示例
MariaDB [yourschema]> SELECT DATE_FORMAT('2016-05-01 12:00:00 AM', '%Y-%m-%d');
+---------------------------------------------------+
| DATE_FORMAT('2016-05-01 12:00:00 AM', '%Y-%m-%d') |
+---------------------------------------------------+
| 2016-05-01 |
+---------------------------------------------------+
1 row in set, 1 warning (0.00 sec)
MariaDB [yourschema]>
关于mysql - 如何删除gridview中数据的Datefield中的时间部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38196038/