如何在vb.net中将生日年份更改为当前年份

时间:2013-03-02 02:03:31

标签: vb.net

如何在vb.net中将生日年份更改为当年?

例如我的生日是2/14/1990 - > 2013年2月14日

但是您更改的日期不是2/14,就像您将其更改为2/20的日期所以它不等于当前日期。

如何将生日年改为当年?

2 个答案:

答案 0 :(得分:0)

使用Date对象的AddYears方法

尝试这样的事情
Dim myBirthday As Date = Date.Parse("2/14/1990")
myBirthday = myBirthday.AddYears(23)

答案 1 :(得分:0)

我的dos centavos

    'what about leap years
    Dim myBirthday As DateTime = #2/29/2000#

    'the following doesn't work 
    ' Dim myBirthdayThisYear As DateTime = New DateTime(DateTime.Now.Year, myBirthday.Month, myBirthday.Day)

    'this works
    Dim myBirthdayThisYear As DateTime = DateSerial(DateTime.Now.Year, myBirthday.Month, myBirthday.Day)