vb.net年龄计算 [英] vb.net age calculation

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

问题描述

我只是想问一些东西,还有一些小代码。





截至目前,我有我需要的代码,除了一个。







我的问题是如何使用vb更新数据库中的年龄。 net?





例如,如果出生日期(MM / dd)= System.Date.Today(MM / dd)那么

年龄+ 1



类似的东西,我如何在vb.net和访问数据库中使用它。

解决方案

为什么需要?将此值存储在数据库中绝对没有意义,因为它在99%的时间内都是不正确的。只存储生日,然后当您需要在视图或打印报告上显示年龄时,从今天的日期和数据库中的DOB显示时计算它。


作为理查德MacCutchan提到,你需要使用查询来计算年龄。您不需要将其值存储在数据库中。

  SELECT  [BirthDate],日期() AS  [今天],DateDiff(  yyyy,[BirthDate],日期()) AS  [年龄] 





更多:

MS访问:日期()功能 [ ^ ]

MS Access:DateDiff功能 [ ^ ]


I just wanna ask something and also a little code too.


As of now I have the codes that i needed except for one.



My question is How can i update the age in the database using vb.net?


For example if the person Birthdate(MM/dd) = System.Date.Today(MM/dd) then
Age + 1

Something like that, how can i use that in vb.net and access database.

解决方案

Why do you need to? There is absolutely no point in storing this value in the database because it will be incorrect 99% of the time. Store only the birthdate, then when you need to display the age on a view or printed report, calculate it at the time of display from today's date and the DOB from the database.


As Richard MacCutchan has mentioned, you need to use query to calculate age. You don't need to store its value in a database.

SELECT [BirthDate], Date() AS [Today], DateDiff("yyyy", [BirthDate], Date())  AS [Age]



More:
MS Access: Date() function[^]
MS Access: DateDiff function[^]


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

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