在Query中计算年和月的年龄 [英] Calculate age in years and months in Query

查看:94
本文介绍了在Query中计算年和月的年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我说两件事 - 我一直在寻找和尝试两天不同的例子,但是我找不到任何工作(我很肯定,因为我缺乏知识),其次,如果任何善于尝试帮助我的人都认为我不需要每一步都能让它发挥作用,他们可能是错的。我想在查询中放置一个字段,该字段将计算当前日期的年和月的年龄,以便我可以将其用于多个表单或报表。我目前使用的(如下所示)只给出了几年,现在我也想要几个月。


年龄:DateDiff(yyyy,[出厂日期] ,Now())+ Int(格式(Now()," mmdd")<格式([从工厂发货的日期],mmdd))


如果是在我的表单或报告中放置一个未绑定的控件会更容易,我也愿意这样做。任何帮助将不胜感激。

First let me say two things--I have been searching and trying different examples for two days and have not been able to make anything I find work (I''m sure due to my lack of knowledge) and second, if anyone that is kind enough to try to help me assumes I won''t need every single step included to make it work, they are probably wrong. I want to put a field in a query that will calculate age in years and months to the current date so that I can use it for more than one form or report. What I am currently using (shown below) gives only years and now I''d like months as well.

Age: DateDiff("yyyy",[Date Shipped from Factory],Now())+Int(Format(Now(),"mmdd")<Format([Date Shipped from Factory],"mmdd"))

If it would be easier to put an unbound control in my form or report, I would be willing to do that as well. Any assistance would be appreciated.

推荐答案

计算月份差异,然后将结果修改为12。
Calculate the difference in months and then mod the result by 12.


显然甚至当准确地完成(我的不是 - 我只是在猜测如何修改我目前的公式)它似乎会给我数字和十分之一而不是数年和数月。我最好猜测如何修改公式,我要么得到3.0,这是几年,但不包括任何月份,44.0这显然只是月数,并且不会真的有用,或者看起来我有3.7,但现在对于我的生活,我不记得我改变了什么。
Apparently even when done accurately (which mine is not--I''m only guessing how to modify my current formula) it appears that will give me numbers and tenths rather than years and months. And with my best guess about how to modify the formula, I''m either getting 3.0, which is the number of years but doesn''t include any months, 44.0 which is apparently the number of months only, and won''t really work or it seems like I got 3.7, but now for the life of me I can''t remember what I changed to get that.


你结合你用来获得岁月使用我在#2后的算法来获得月份。当你把它们放在一起时,就可以得到年份和月份。
You combine what you use to get the years with my algorithm in post #2 to get the months. When you put them together, you get the years and months.


这篇关于在Query中计算年和月的年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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