数据库中的日期 [英] Date in database
问题描述
在我办公室的机器上,我将计算机设置更改为英语(英国),所以
日期格式为dd / mm / yyyy,而不是美国的mm / dd / yyyy。
在Access或SQL Server中都会出现此问题。
在数据库中,我有一个带有日期/时间列的表。数据库是
也位于设置为dd / mm / yyyy的机器上。
当我输入日期7/1/08(如2008年1月7日) ),它将它作为1/7/08而不是7/1/08存储在
数据库中。为什么会这样呢?如何将数据库存储为7/1/08?
谢谢。
您可以将区域日期格式设置为您喜欢的任何格式,但是当使用SQL来插入或更新数据时,您需要必须使用SQL Server的yyyy-mm-dd格式或
mm / dd / yyyy格式进行访问。
如果使用Addnew方法,则分配对于该字段的日期值,您必须使用
a日期变量类型:
dim strDate as string
strDate = date
open recordset" rs"
rs.addnew
rs!DateField = strDate < br $>
rs.update
上面不会工作!!! (对于mm / dd / yyyy以外的任何日期格式)
更改为:
dim dteDate as date
dteDate = date
打开记录集rs
rs.addnew
rs!DateField = dteDate
rs.update
这个例子非常简单,你可以直接指定Date,但是在使用时
计算日期最有可能需要变量。
构建带日期的SQL:
sSQL ="插入MyTable(Mydate)值(
sSQL = sSQL&"''"& format
(date," yyyy- mm-dd")&"'')"
对于Access更改为:
sSQL = sSQL& "" &安培; format
(date," mm / dd / yyyy")& "''')"
HTH Saga
-
" fniles" < fn ******* @ SPAMMEpfmail.com在留言中写道
新闻:%2 **************** @ TK2MSFTNGP03.phx.gbl ...
在我办公室的机器上,我将计算机设置更改为英语(英国),所以日期格式为
dd / mm / yyyy而不是mm / dd / yyyy for US。
此问题发生在Access或SQL Server中。
在数据库中,我有一个日期/时间表柱。该数据库位于一台机器上,即b $ b设置为dd / mm / yyyy。
当我输入日期7/1/08(如2008年1月7日) ),它将它作为1/7/08存储在数据库中,而不是8/1/08的
。为什么会这样,我怎样才能让数据库存储为7/1/08?
谢谢。
On my machine in the office I change the computer setting to English (UK) so
the date format is dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is
located on a machine that is set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the
database as 1/7/08 instead of 7/1/08. Why is it like that and how can I make
the database stores it as 7/1/08 ?
Thank you.
You can set the regional date format to anything you like, but when using SQLs to
insert or update data, you must use the yyyy-mm-dd format for SQL Server or the
mm/dd/yyyy format for Access.
If using the Addnew method then assigning the date value to the field, you must use
a date variable type:
dim strDate as string
strDate = date
open recordset "rs"
rs.addnew
rs!DateField = strDate
rs.update
The above wont work!!! (for any date format other than mm/dd/yyyy)
Change it to this:
dim dteDate as date
dteDate = date
open recordset "rs"
rs.addnew
rs!DateField = dteDate
rs.update
This example is so trivial, that you can assign Date directly, but when using
calculated dates the variable will most likely be needed.
To build an SQL with a date:
sSQL = "insert into MyTable (Mydate) values ("
sSQL = sSQL & "''" & format
(date, "yyyy-mm-dd") & "'')"
For Access change that to:
sSQL = sSQL & "''" & format
(date, "mm/dd/yyyy") & "'')"
HTH Saga
--
"fniles" <fn*******@SPAMMEpfmail.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...On my machine in the office I change the computer setting to English (UK) so the date format is
dd/mm/yyyy instead of mm/dd/yyyy for US.
This problem happens in either Access or SQL Server.
In the database I have a table with Date/time column. The database is located on a machine that is
set to dd/mm/yyyy also.
When I enter date 7/1/08 (as in January 7, 2008), it stores it in the database as 1/7/08 instead
of 7/1/08. Why is it like that and how can I make the database stores it as 7/1/08 ?
Thank you.
这篇关于数据库中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!