日期时间和转换函数在表设计时在 MS Access 365 中不可用

发布于 2025-01-10 02:38:11 字数 757 浏览 0 评论 0原文

我试图简单地将文本字段转换为 MS Access 365 中的日期时间值。这应该很简单。但是我似乎无法访问 Date()、DateValue() 等函数。

我想要一些可以只传递一些文本并将其转换为日期时间类型的东西。我的数据如下所示: 输入图片这里的描述

我使用了公式:我使用这个公式得到了这个:Left$([DateText],InStr(1,[DateText]," - ")) 从 DateText 字段中删除时间。

现在我想使用 DateTextWithTimeRemoved 字段中的数据添加一个日期/时间类型的新字段。

表设计视图(还显示可用的转换函数)如下所示: 输入图片这里的描述

日期函数如下:

,从几年前开始,我记得使用过 CDate() 或 Date() 或 DateValue() 等函数或其他函数,但它们就是不存在。我是否需要安装一些东西才能获得这些功能?

I'm trying to simply convert a text field into a datetime value in MS Access 365. This should be simple. However I don't seem to have access to functions like Date(), DateValue().

I want something where I can just pass some text in and it converts to a datetime type. My data looks like this:
enter image description here

I used the formula: I used this formula to get this: Left$([DateText],InStr(1,[DateText]," - "))
to remove the time from the DateText field.

Now I want to add a new field which is a date/time type using the data in the DateTextWithTimeRemoved field.

The table design view (also showing the conversion functions available) is like this:
enter image description here

And the date functions are these:
enter image description here

And so, from years ago I remember using functions like CDate() or Date() or DateValue() or what have you, but they're just not there. Do I have to install something to get these functions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

韬韬不绝 2025-01-17 02:38:11

假设您想保留问题中显示的相同表字段:

  1. 备份当前表。

  2. DateThatIsAnActualDate 字段的数据类型更改为日期/时间,并将 DateTextWithTimeRemoved 更改为短文本。

  3. 创建更新查询。 (创建 -> 查询设计 -> 在查询类型下选择更新。)

  4. 添加表(成员)

     字段:DateTextWithTimeRemoved
     表:成员
     更新至: 
    

Left([DateText],InStr(1,[DateText]," -"))

下一列

    Field: DateThatIsAnActualDate
    Table: members
    Update To: 

Format(DateValue(Left( [DateText],(InStr(1,[DateText]," -")))),"dd/mm/yyyy")

  1. 单击“运行”!

  2. 单击“是”进行确认。

  3. 全部完成。检查members表中的记录。

Assuming you want to keep the same Table fields shown in your question:

  1. Make a backup of your current table.

  2. Change the Data Type of the DateThatIsAnActualDate field to Date/Time and DateTextWithTimeRemoved to Short Text.

  3. Create an an Update Query. (Create -> Query Design -> select Update under Query Type.)

  4. Add your Table (members)

     Field: DateTextWithTimeRemoved
     Table: members
     Update To: 
    

Left([DateText],InStr(1,[DateText]," -"))

next column

    Field: DateThatIsAnActualDate
    Table: members
    Update To: 

Format(DateValue(Left([DateText],(InStr(1,[DateText]," -")))),"dd/mm/yyyy")

  1. Click Run !

  2. Click Yes to confirm.

  3. All done. Check the records in the members table.

温柔戏命师 2025-01-17 02:38:11

首先,忘记计算字段。使用查询,这就是它们的用途。表格是用于数据的。

其次,表达式生成器毫无希望。我从来没有发现它有用。

接下来,轻松转换为真实日期值所需的只是删除破折号。

TextDate = "10 Dec 2020 - 16:52"

? Replace(TextDate, "-", "")
10 Dec 2020  16:52

可以这样转换:

' Date only:
? DateValue(Replace(TextDate, "-", ""))
2020-12-10

' Date and time:
? CDate(Replace(TextDate, "-", ""))
2020-12-10 16:52

现在,您的查询可能如下所示:

Select
    ID,
    Username,
    DateValue(Replace(TextDate, "-", "")) As TrueDate,
    CDate(Replace(TextDate, "-", "")) As TrueDateTime
From
    Members

注意,日期/时间值不带格式。将此应用仅用于显示,因此如果默认格式(Windows 设置的格式)不适合,请在需要时调整“格式”属性(查看数据的表单/报告)。

Format: dd/mm/yyyy

默认为:

Format: Short Date

First, forget about the calculated fields. Use queries, that's what they are for. Tables are for data.

Second, the Expression Builder is hopeless. I have never found it useful.

Next, all you need for an easy conversion to true date values, is to remove the dash.

TextDate = "10 Dec 2020 - 16:52"

? Replace(TextDate, "-", "")
10 Dec 2020  16:52

This can be converted like this:

' Date only:
? DateValue(Replace(TextDate, "-", ""))
2020-12-10

' Date and time:
? CDate(Replace(TextDate, "-", ""))
2020-12-10 16:52

Now, your query could look this this:

Select
    ID,
    Username,
    DateValue(Replace(TextDate, "-", "")) As TrueDate,
    CDate(Replace(TextDate, "-", "")) As TrueDateTime
From
    Members

Note, that date/time values carry no format. Apply this for display only, so adjust the Format property where needed (the forms/reports where you view the data), if the default format (that of your Windows settings) doesn't fit.

Format: dd/mm/yyyy

The default is:

Format: Short Date
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文