Quick Reference file, simple and practical.
(1) display and write the complete Date and Time:
. Aspx. CS (for writing ):
String strsql = "update data table name set date field name = '" + datetime. Now. tostring ("yyyy/mm/dd hh: mm: SS") + "'";
. Aspx (for display ):
<Asp: Label id = "label1" runat = "server" text = '<% # eval ("Date Field name", "{0: yyyy/mm/dd tt hh: MM: SS} ") %> '> </ASP: Label>
Result displayed on the label after execution: 19:29:51
(2) display and write date, excluding the time:
. Aspx. CS (for writing ):
String strsql = "update data table name set date field name = '" + datetime. Today. to1_datestring () + "'";
. Aspx (for display ):
<Asp: Label id = "label1" runat = "server" text = '<% # eval ("Date Field name", "{0: yyyy/mm/dd }") %> '> </ASP: Label>
Result displayed on the label after execution: 2007/07/06
In the preceding example, the "Date Field name" Field of the database uses the datetime type and the tested database uses SQL Server 2005.