日期时间问题 [英] DateTime Problems

查看:84
本文介绍了日期时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我本地计算机中的日期设置为dd / MM / yyyy格式。当我在
中在MS-Access数据库表中插入日期时,它会以上面的

格式填充。对于例如如果日期是,例如,2007年3月8日,那么数据库表中会填充




08/03/2007


换句话说,首先是显示日期,然后是月份&最后是

年,但是当我在ASP.NET&使用DatePart,尝试

提取日期&像这样的月份(假设数据库表中的日期记录

存储在名为dtOrderDate的变量中)


Response.Write(" Day: &&;& DatePart(" d",dtOrderDate))

Response.Write(" Month:"& DatePart(" m",dtOrderDate))


第一个Response.Write输出当天为03&那个月是08,其中

因为它应该是另一种方式,即白天应该是08而

月份应该是03。当我的时候价值得到反转
只做Response.Write(dtOrderDate)。


有人可以指出我错过了什么吗?

The date in my local machine is set to the dd/MM/yyyy format. When I
insert a date in a MS-Access DB table, it gets populated in the above
format. For e.g. if the date is, say, 8th March 2007, it gets
populated in the DB table as

08/03/2007

In other words, first the day is shown, then the month & finally the
year but when I retrieve it in ASP.NET & using DatePart, try to
extract the day & the month like this (assume that the date record
from the DB table is stored in a variable named dtOrderDate)

Response.Write("Day: " & DatePart("d", dtOrderDate))
Response.Write("Month: " & DatePart("m", dtOrderDate))

the first Response.Write outputs the day as 03 & the month as 08 where
as it should be the other way round i.e. the day should be 08 whereas
the month should be 03. The day & month values get reversed when I
just do Response.Write(dtOrderDate).

Can someone please point out what am I missing?

推荐答案

3月10日下午5:03,r ... @ rediffmail.com写道:
On Mar 10, 5:03 pm, r...@rediffmail.com wrote:

本地计算机中的日期设置为dd / MM / yyyy格式。当我在
中在MS-Access数据库表中插入日期时,它会以上面的

格式填充。对于例如如果日期是,例如,2007年3月8日,那么数据库表中会填充




08/03/2007


换句话说,首先是显示日期,然后是月份&最后是

年,但是当我在ASP.NET&使用DatePart,尝试

提取日期&像这样的月份(假设数据库表中的日期记录

存储在名为dtOrderDate的变量中)


Response.Write(" Day: &&;& DatePart(" d",dtOrderDate))

Response.Write(" Month:"& DatePart(" m",dtOrderDate))


第一个Response.Write输出当天为03&那个月是08,其中

因为它应该是另一种方式,即白天应该是08而

月份应该是03。当我这个价值得到反转时,我只需要做一个Response.Write(dtOrderDate)。


有人可以指出我错过了什么吗?
The date in my local machine is set to the dd/MM/yyyy format. When I
insert a date in a MS-Access DB table, it gets populated in the above
format. For e.g. if the date is, say, 8th March 2007, it gets
populated in the DB table as

08/03/2007

In other words, first the day is shown, then the month & finally the
year but when I retrieve it in ASP.NET & using DatePart, try to
extract the day & the month like this (assume that the date record
from the DB table is stored in a variable named dtOrderDate)

Response.Write("Day: " & DatePart("d", dtOrderDate))
Response.Write("Month: " & DatePart("m", dtOrderDate))

the first Response.Write outputs the day as 03 & the month as 08 where
as it should be the other way round i.e. the day should be 08 whereas
the month should be 03. The day & month values get reversed when I
just do Response.Write(dtOrderDate).

Can someone please point out what am I missing?



我想,这意味着数据库中的日期是错误的?你怎么用
在数据库中插入日期(sql查询格式)?尝试插入

''2006-03-08''看看会发生什么......

I suppose, it means the date in the database is wrong? How do you
insert the date in the database (sql query format)? Try to insert
''2006-03-08'' and see what happen...


" Alexey Smirnov" ; < al ************ @ gmail.comwrote in message

news:11 ****************** ****@v33g2000cwv.googlegr oups.com ...
"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...

我想,这意味着数据库中的日期是错误的?你怎么用
在数据库中插入日期(sql查询格式)?尝试插入

''2006-03-08'',看看会发生什么......
I suppose, it means the date in the database is wrong? How do you
insert the date in the database (sql query format)? Try to insert
''2006-03-08'' and see what happen...



或者,更好的是,插入' ''2006年3月'''你将*从来没有*有问题

之后......

Or, even better, insert ''08 Mar 2006'' and you''ll *never* have a problem
after that...


3月10日,9日:晚上10点,Alexey Smirnov < alexey.smir ... @ gmail.comwrote:
On Mar 10, 9:10 pm, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:

3月10日下午5:03,r ... @ rediffmail.com写道:


On Mar 10, 5:03 pm, r...@rediffmail.com wrote:



本地计算机中的日期设置为dd / MM / yyyy格式。当我在
中在MS-Access数据库表中插入日期时,它会以上面的

格式填充。对于例如如果日期是,例如,2007年3月8日,它将在数据库表中填入


The date in my local machine is set to the dd/MM/yyyy format. When I
insert a date in a MS-Access DB table, it gets populated in the above
format. For e.g. if the date is, say, 8th March 2007, it gets
populated in the DB table as


08/03 / 2007
08/03/2007


换句话说,首先显示日期,然后是月份&最后是

年,但是当我在ASP.NET&使用DatePart,尝试

提取日期&像这样的月份(假设数据库表中的日期记录

存储在名为dtOrderDate的变量中)
In other words, first the day is shown, then the month & finally the
year but when I retrieve it in ASP.NET & using DatePart, try to
extract the day & the month like this (assume that the date record
from the DB table is stored in a variable named dtOrderDate)


Response.Write(" Day:"& DatePart(" d",dtOrderDate))

Response.Write(" Month:"& DatePart(" m",dtOrderDate) ))
Response.Write("Day: " & DatePart("d", dtOrderDate))
Response.Write("Month: " & DatePart("m", dtOrderDate))


第一个Response.Write输出当天为03&那个月是08,其中

因为它应该是另一种方式,即白天应该是08而

月份应该是03。当我用
执行Response.Write(dtOrderDate)时,月值会反转。
the first Response.Write outputs the day as 03 & the month as 08 where
as it should be the other way round i.e. the day should be 08 whereas
the month should be 03. The day & month values get reversed when I
just do Response.Write(dtOrderDate).


有人可以指出我错过了什么吗?
Can someone please point out what am I missing?



我想,这意味着数据库中的日期是错误的?你怎么用
在数据库中插入日期(sql查询格式)?尝试插入

''2006-03-08''看看会发生什么......-隐藏引用的文字 -


- 显示引用的文字 -


I suppose, it means the date in the database is wrong? How do you
insert the date in the database (sql query format)? Try to insert
''2006-03-08'' and see what happen...- Hide quoted text -

- Show quoted text -



Alexey,这就是我在Access数据库表中插入记录的方式:


strSQL =" INSERT INTO CustomerDetails( CName,Mail,Address,

OrderDate)VALUES(?,?,?,?)"


oledbCmd =新OleDbCommand(strSQL,oledbConn)


使用oledbCmd

.Parameters.AddWithValue("?",strName)

.Parameters.AddWithValue("? ",strEMail)

.Parameters.AddWithValue("?",strAddress)

.Parameters.AddWithValue("?",DateTime.Now.ToString )

结束


请注意,我将日期(这是最后一个参数)转换为

字符串。如果我只使用DateTime.Now(

数据库表中列的数据类型是日期/时间),那么ASP.NET会生成一个错误,说明数据

类型标准表达不匹配。


还有其他想法/建议吗?

Alexey, this is how I am inserting records in the Access DB table:

strSQL = "INSERT INTO CustomerDetails (CName, Mail, Address,
OrderDate) VALUES (?, ?, ?, ?)"

oledbCmd = New OleDbCommand(strSQL, oledbConn)

With oledbCmd
.Parameters.AddWithValue("?", strName)
.Parameters.AddWithValue("?", strEMail)
.Parameters.AddWithValue("?", strAddress)
.Parameters.AddWithValue("?", DateTime.Now.ToString)
End With

Note that I am casting the date (which is the last parameter) into
string. If I just use DateTime.Now (the data type of the column in the
DB table is Date/Time), then ASP.NET generates an error saying Data
type mismatch in criteria expression.

Any other ideas/suggestions?


这篇关于日期时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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