如何使用VB.NET从包含from_date和to_date的数据表中计算年数,月数和天数? [英] How can I Calculate Number of years , monthes and days from data table contains from_date and to_date using VB.NET?

查看:145
本文介绍了如何使用VB.NET从包含from_date和to_date的数据表中计算年数,月数和天数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一下时间间隔和间隔之间的交集

take in your consideration Intersection of intervals and gabes between intervals

推荐答案

从数据库中检索日期时,请执行以下操作:

When you retrieve the dates from the database, do this:

Dim span As TimeSpan = toDate - FromDate



需要注意的一件事是,TimeSpan对象没有数月的表示形式,因此您将必须通过确定每个月有多少天来估算它(大多数人在这种情况下使用30天).因此,要找到TimeSpan对象涵盖的月份和日期,您必须执行以下操作:



One thing to be aware of is that the TimeSpan object does not have a representation for months, so you''re going to have to estimate it by establishing how many days are n a month (most folks use 30 in a situation like this). So, to find the months and days covered by the TimeSpan object, you''d have to do this:

Dim months As Integer = span.Days / 30
Dim days As Integer = span.Days - (months * 30)


您可以使用Date.Compare函数通过传递两个日期来比较两个日期作为参数.请参见示例:
You can use Date.Compare function tow compare two Date by passing Two Date as a parameter.See Example :
Date.Compare(Date1, Date2)


或者还有另一种比较两个日期的方法.您可以使用DateDiff函数
Compare相比,它更适合.参见示例:


Or there is another way to Compare Two Dates. You can use DateDiff Function
which is more suitable as compare to Compare. See Example :

DateDiff(DateInterval.Day, Date1, Date2)


希望对您有帮助. :)

--MKB


I hope it will help you. :)

--MKB


这篇关于如何使用VB.NET从包含from_date和to_date的数据表中计算年数,月数和天数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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