将部分文本字符串转换为时间 [英] Convert part of text string to Time

查看:79
本文介绍了将部分文本字符串转换为时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从Excel工作表导入Access的数据。我遇到问题的领域叫做[SaleTime]。它包含物品称重的日期和时间。这个字符串是这样的:

20120314080253

我的查询中有两个字段。一个将第一部分转换为日期,另一个将第二部分转换为时间。它在Access中效果很好。


Weigh_Date:DateSerial(左([SaleTime],4),Mid([SaleTime],5,2),Mid([SaleTime],7, 2))


Weigh_Time:TimeSerial(右(左([SaleTime],10),2),右(左([SaleTime],12),2),右([ Saletime],2))

我的问题是当我在Excel中创建一个新表格的ODBC链接时,所有字段的时间显示为12:00:00 AM。 br />

我做错了什么?


非常感谢,Sharon

I have data that I import from an Excel sheet into Access. the field I have problems with is called [SaleTime]. It contains the date and time of the article being weighed. The string comes in like this:
20120314080253
I have two fields in my query. One converts the first part to a date and the other converts the second part to Time. It works great in Access.

Weigh_Date: DateSerial(Left([SaleTime],4),Mid([SaleTime],5,2),Mid([SaleTime],7,2))

Weigh_Time: TimeSerial(Right(Left([SaleTime],10),2),Right(Left([SaleTime],12),2),Right([Saletime],2))

My problem is when I create an ODBC link to a new sheet in Excel, the time shows as 12:00:00 AM in all the fields.

What am I doing wrong?

Thanks a lot, Sharon

推荐答案

您是将这两个值一起添加并存储在访问的单个字段中吗? Access有一个名为DateTime的字段类型,用于存储日期和时间信息。两者都可以(我认为在大多数情况下应该)只存储在1个字段中。听起来你的导出只导出日期部分。
Are you adding these 2 values together and storing them in a single field in access? Access has one field type called DateTime used for storing both date and time information. Both can (and I would think in most cases should) be stored in only 1 field. It sounds like your export is only exporting the date part.


如果你链接到一个新的表,那么我预计其中没有数据。凌晨12:00:00(或午夜)实际上是时间相当于0。
If you''re linking to a new sheet then I expect there is no data therein. 12:00:00 AM (or midnight) is actually the time-equivalent of 0.


你好。我正在尝试创建日期字段和单独的时间字段。客户需要根据时间提取数据(员工轮班工作)。我现在已经意识到,在使用Microsoft Query之后,数据实际上是这样的:

09/03/2012 12:00:00 AM(日期字段)

时间字段看起来像这样:00/01/1900 12:00:00 AM。

我完全难过了。

你能帮忙吗?在此期待感谢:)
Hi there. I am trying to Create a Date Field and a separate Time Field. The client needs to extract data based upon Time (the staff work in shifts). I have now realized, after using Microsoft Query, that the data actually comes in like this:
09/03/2012 12:00:00 AM (Date Field)
and the Time field looks like this: 00/01/1900 12:00:00 AM.
I am totally stumped.
Can you help? Thanks in anticipation :)


这篇关于将部分文本字符串转换为时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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