退休日期功能基于出生日期 [英] retirement date function on the basis of date of birth

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

问题描述

我正在研究vb.net中的mysql项目。我想在填写出生日期时自动生成退休日期,年龄为60岁。即

如果出生日期 15/1/1950 那么退休日期将 31/1 / 2010



如果出生日期 01/1/1950 那么退休日期 31/12/2009

I am working on an mysql project in vb.net . I want to generate the retirement date automatically at the age of 60 years while filling the date of Birth. i.e.
if the Date of birth is 15/1/1950 then the date of retirement will be 31/1/2010
and
if the date of birth is 01/1/1950 then the date of retirement will be 31/12/2009

推荐答案

您可以使用DateTime.Addyears方法计算提前60年的日期,然后减去1天。
You can use the DateTime.Addyears method to calculate the date 60 years ahead, then subtract 1 day.


vba代码



函数RetiringDate(DOB As Date)As Date

Dim dob_day,dob_mnth,dob_yr,ret_day,ret_mnth,ret_yr As Long



dob_day = Day(DOB)

dob_mnth =月(DOB)

dob_yr =年(DOB)



如果dob_day = 1且dob_mnth = 1那么

ret_mnth = 12

ret_yr =(dob_yr + 60) - 1

ElseIf dob_day = 1然后

ret_mnth = dob_mnth - 1

ret_yr =(dob_yr + 60)

否则

ret_mnth = dob_mnth

ret_yr =(dob_yr + 60)

结束如果



如果ret_mnth = 1或者ret_mnth = 3或者ret_mnth = 5或者ret_mnth = 7或者_

ret_mnth = 8或者ret_mnth = 10或者ret_mnth = 12然后

ret_day = 31

ElseIf ret_mnth<> 2然后

ret_day = 30

否则

ret_day = 28

结束如果



RetiringDate = CDate(ret_yr&/&ret_mnth&/&ret_day)

结束函数
vba code

Function RetiringDate(DOB As Date) As Date
Dim dob_day, dob_mnth, dob_yr, ret_day, ret_mnth, ret_yr As Long

dob_day = Day(DOB)
dob_mnth = Month(DOB)
dob_yr = Year(DOB)

If dob_day = 1 And dob_mnth = 1 Then
ret_mnth = 12
ret_yr = (dob_yr + 60) - 1
ElseIf dob_day = 1 Then
ret_mnth = dob_mnth - 1
ret_yr = (dob_yr + 60)
Else
ret_mnth = dob_mnth
ret_yr = (dob_yr + 60)
End If

If ret_mnth = 1 Or ret_mnth = 3 Or ret_mnth = 5 Or ret_mnth = 7 Or _
ret_mnth = 8 Or ret_mnth = 10 Or ret_mnth = 12 Then
ret_day = 31
ElseIf ret_mnth <> 2 Then
ret_day = 30
Else
ret_day = 28
End If

RetiringDate = CDate(ret_yr & "/" & ret_mnth & "/" & ret_day)
End Function


这篇关于退休日期功能基于出生日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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