日期错误地保存错误。 DD和MM交换了一轮? [英] Dates incorrectly being saved incorrectly. DD and MM swapped round ?

查看:92
本文介绍了日期错误地保存错误。 DD和MM交换了一轮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我创建的存储过程不正确

将日期保存到表中。似乎日期和月份正在交换,例如:日期应该是4月12日(2005年4月12日)

将在12月4日(2005年12月4日)保存。


存储过程中使用的参数来自VB6应用程序,我对此进行了修改,因此格式为yyyymmdd hh:mm:ss。 VB中的整行




Parameters.Append .CreateParameter(" date_of_call",adChar ,, 17,

格式(firstCallDateTime,yyyymmdd hh:mm:ss))

当我运行我的VB应用程序时它工作正常,存储过程中的语法

是,


创建程序dbo.spUpdValues

@data_id int,

@date_of_call datetime


as


更新数据

SET date_of_call = CONVERT(char,@ date_of_call,101)

其中data_id = @ data_id


是否因为转换格式使用美国日期格式?我不知道为什么因为我无法使用我自己的电脑重现这个错误,因为

日期保存正确,我也可以确认它是'没有发生在每个人身上

谁使用该应用程序。如果它发生在特定用户身上,那么原因可能是什么?
。我已经检查了区域设置,一切似乎都很好。


任何有关可能做到这一点的想法,因为我正在努力调查

any进一步。


调试我直接运行存储过程,手动输入

变量 - 再次没问题。另外,以下SQL语句显示没有

问题...


声明@date_of_call日期时间

设置@date_of_call ='' 20041101 08:30:00''


选择CONVERT(char,@ date_of_call,101)

选择CONVERT(char,@ date_of_call,106)


------------------------------

11 / 01/2004


(1行受影响)


--------------- ---------------

2004年11月01日


(1行受影响)


我们非常感谢任何帮助。


***通过Developersdex发送 http://www.developersdex.com ***

For some reason a stored procedure which I have created is incorrectly
saving the date to the table. It seems the day and month are being
swapped around e.g. a date which should be the 12th April (12/04/2005)
is saving as the 4th December (04/12/2005).

The parameter used in the stored procedure comes from a VB6 app, I
amended this so the format was "yyyymmdd hh:mm:ss". The full line in VB
being,

Parameters.Append .CreateParameter("date_of_call", adChar, , 17,
Format(firstCallDateTime, "yyyymmdd hh:mm:ss"))

When I run my VB app it works fine, the syntax in the stored procedure
is,

CREATE PROCEDURE dbo.spUpdValues

@data_id int,
@date_of_call datetime

as

update data
SET date_of_call = CONVERT(char, @date_of_call, 101)
where data_id=@data_id

Is it because the convert format is using an american date format ? I
can''t see why as I can''t reproduce this error using my own PC as the
date saves correctly, I can also confirm it''s not happening to everybody
who uses the app. If it is happening for specifc users then what could
be the cause. I''ve checked Regional Settings and all seems fine there.

Any ideas on what could be doing this as I''m struggling to investigate
any further.

To debug I ran the stored procedure direct, manually inputting the
variable - again no problem. Also, the following SQL statment shows no
problem...

declare @date_of_call datetime
set @date_of_call = ''20041101 08:30:00''

select CONVERT(char, @date_of_call, 101)
select CONVERT(char, @date_of_call, 106)

------------------------------
11/01/2004

(1 row(s) affected)

------------------------------
01 Nov 2004

(1 row(s) affected)

Any help would be much appreciated.

*** Sent via Developersdex http://www.developersdex.com ***

推荐答案

MSSQL在内部存储日期以二进制格式 - 任何客户端(包括查询分析器等)中的显示格式

由客户端定义,

不是服务器。请参阅此文章:

http:// www。 karaszi.com/sqlserver/info_datetime.asp


格式化日期的最佳方法通常是在客户端

应用程序中进行,因为它可以访问客户的区域设置。


Simon

MSSQL stores dates internally in a binary format - the display format
in any client (including Query Analyzer etc.) is defined by the client,
not the server. See this article:

http://www.karaszi.com/sqlserver/info_datetime.asp

The best way to format dates is usually to do it in the client
application, because it has access to the client''s regional settings.

Simon


2005年4月26日星期二10:36:00 GMT,Robert Zirpolo写道:


(snip)
On Tue, 26 Apr 2005 10:36:00 GMT, Robert Zirpolo wrote:

(snip)
存储过程中使用的参数来自VB6应用程序,我是修改了这个格式是yyyymmdd hh:mm:ss。
The parameter used in the stored procedure comes from a VB6 app, I
amended this so the format was "yyyymmdd hh:mm:ss".




嗨罗伯特,


这个格式不是保证安全的格式之一。格式。我必须承认

我还没有发现任何有利的证据证明这种格式是错误的,但由于它不能保证,它可能被解释为错误。


这些格式是安全的:


* yyyymmdd - 仅限日期(注意:没有破折号,斜线,点或其他
interpuction)


* yyyy-mm-ddThh:mm:ss - 数据和时间(注意:需要破折号

之间日期的一部分;时间部分之间的冒号和

大写T从时间部分分开日期)


* yyyy-mm-ddThh :mm:ss.ttt - 与上面相同,但包括毫秒


尝试使用其中一种格式,看看是否能解决问题。


Best,Hugo

-

(删除_NO_和_SPAM_以获取我的电子邮件地址)



Hi Robert,

This format is not one of the guaranteed "safe" formats. I must admit that
I have not yet found any positive evidence that this format IS interpreted
wrong, but since it''s not guaranteed, it MIGHT be interpreted wrong.

These formats are safe:

* yyyymmdd - for date only (note: no dashes, slashes, dots, or other
interpuction)

* yyyy-mm-ddThh:mm:ss - for data and time (note: dashes are required
between the parts of the date; colons between the parts of the time and an
uppercase T seperates the date from the time part)

* yyyy-mm-ddThh:mm:ss.ttt - same as above, but including milliseconds

Try using one of these formats and see if that solves your problem.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


Robert Zirpolo(ro************@moorestephens.com)写道:
Robert Zirpolo (ro************@moorestephens.com) writes:
对于一些rea儿子我创建的存储过程不正确
将日期保存到表中。似乎日期和月份正在交换,例如日期应该是4月12日(2005年4月12日)
保存为12月4日(2005年12月4日)。

存储过程中使用的参数来自一个VB6应用程序,我
修改了这个格式是yyyymmdd hh:mm:ss。 VB中的整行是

Parameters.Append .CreateParameter(" date_of_call",adChar ,, 17,
格式(firstCallDateTime," yyyymmdd hh:mm: ss"))


这确实是日期时间值的安全格式。不过,你要
应该使用adDBTimeStamp,以便通过网络传递二进制值



CREATE PROCEDURE dbo.spUpdValues

@ dat_id int,
@ date_of_call datetime


更新数据
SET date_of_call = CONVERT(char,@ date_of_call,101 )
其中data_id = @ data_id


如果data.date_of_call是datetime,则无需使用转换为

all。把它带走。

是因为转换格式是使用美国日期格式吗?我无法理解为什么我无法使用我自己的电脑重现此错误,因为
日期保存正确,我也可以确认它并非发生在每个人身上
谁使用该应用程序。如果它发生在特定用户身上,那么可能是什么原因。我已经检查了区域设置,一切似乎都很好。
For some reason a stored procedure which I have created is incorrectly
saving the date to the table. It seems the day and month are being
swapped around e.g. a date which should be the 12th April (12/04/2005)
is saving as the 4th December (04/12/2005).

The parameter used in the stored procedure comes from a VB6 app, I
amended this so the format was "yyyymmdd hh:mm:ss". The full line in VB
being,

Parameters.Append .CreateParameter("date_of_call", adChar, , 17,
Format(firstCallDateTime, "yyyymmdd hh:mm:ss"))
That''s indeed a safe format for datetime values. Nevertheless, you
should use adDBTimeStamp instead, so that binary values are passed
over the wire.
CREATE PROCEDURE dbo.spUpdValues

@data_id int,
@date_of_call datetime

as

update data
SET date_of_call = CONVERT(char, @date_of_call, 101)
where data_id=@data_id
If data.date_of_call is datetime, there is no need to use convert at
all. Just take it away.
Is it because the convert format is using an american date format ? I
can''t see why as I can''t reproduce this error using my own PC as the
date saves correctly, I can also confirm it''s not happening to everybody
who uses the app. If it is happening for specifc users then what could
be the cause. I''ve checked Regional Settings and all seems fine there.




SQL Server不按区域设置,也不在服务器上,

也不是客户。相反,SQL Server通过dateformat和语言

设置。不同的用户可以使用不同的默认语言。

-

Erland Sommarskog,SQL Server MVP, es **** @ sommarskog.se


SQL Server SP3联机丛书
http://www.microsoft.com/sql/techinf...2000/books.asp


这篇关于日期错误地保存错误。 DD和MM交换了一轮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆