求精确计算两个日期之间的年数的函数

c_delight 2006-01-18 10:30:17
比如
2000/01/12 - 2006/01/11 结果是5年
2000/01/12 - 2006/01/12 结果是6年

谢谢

...全文
164 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxufewbt 2006-01-19
  • 打赏
  • 举报
回复
Snowdust(雪尘) 正解
yzg100 2006-01-19
  • 打赏
  • 举报
回复
Dim d1 As Date = Date.Parse("2005-11-25")
Dim d2 As Date = Date.Parse("2006-11-26")
Dim strDay As String = d1.Subtract(d2).ToString
相差天数出来,要怎么转年就自己来算了。
Snowdust 2006-01-18
  • 打赏
  • 举报
回复
Dim fromDate As DateTime = New DateTime(2000, 1, 12)
Dim toDate As DateTime = New DateTime(2006, 1, 11)
Dim year As Integer
year = toDate.Year - fromDate.Year
If toDate.Month < fromDate.Month Then
year = year - 1
ElseIf toDate.Month = fromDate.Month Then
If toDate.Day < fromDate.Day Then
year = year - 1
End If
End If
MessageBox.Show(year.ToString)

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧