如何将当前日期插入数据库 [英] how to insert current date into database
本文介绍了如何将当前日期插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在button_click事件
解决方案
中将当前系统日期插入到表中,以便检索当前日期,您可以在sql中使用getdate()函数。
表示各种日期格式:
参考:
[ ^ ]
http://www.technoreader.com/SQL-Server- Date-Time-Format.aspx [ ^ ]
http://www.simple-talk.com/sql/learn-sql-server/robyn-pages-sql-server-datetime-workbench/ [ ^ ]
使用所有可能的相关技术标记问题总是更好(包括RDBMS)您正在使用。
我不建议您使用.Net / C#语法/代码来保存当前日期。因为在生产中,Web服务器和数据库服务器的时区可能不同。
使用以下语法获取数据库服务器的当前日期时间。
1)SQL Server
http://www.w3schools.com/sql/func_getdate.asp
2)Oracle
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/ functions172.htm
3)MySQL
http://www.w3schools.com/sql/func_now.asp
4)DB2
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0005870.html 一>
对于SQL:getdate();
对于C#:DateTime 。现在;或DateTime.ToDay;
如果字段是varchar那么,
DateTime.Now.ToString(dd / MM / yyyy);
或
DateTime.ToDay.ToString(dd / MM / yyyy);
How to insert current system date into table on button_click event
解决方案
for retrieving current date you can use getdate() function in sql .
for the various date formats refer:
refer:
[^]
http://www.technoreader.com/SQL-Server-Date-Time-Format.aspx[^]
http://www.simple-talk.com/sql/learn-sql-server/robyn-pages-sql-server-datetime-workbench/[^]
Its always better to Tag a Question with all possible related technologies(including RDBMS) you are using.
I do not recommend you to use .Net/C# syntax/code to save Current Date. Because on Production, Time-Zone of your Web-Server and Database-Server may not be same.
Use below syntax to get Current DateTime of your DB-Server.
1) SQL Server
http://www.w3schools.com/sql/func_getdate.asp
2) Oracle
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions172.htm
3) MySQL
http://www.w3schools.com/sql/func_now.asp
4) DB2
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0005870.html
For SQL :getdate();
For C# :DateTime.Now; or DateTime.ToDay;
If the field is varchar then,
DateTime.Now.ToString("dd/MM/yyyy");
or
DateTime.ToDay.ToString("dd/MM/yyyy");
这篇关于如何将当前日期插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文