如何在文本框周围使用DateDiff计算?需要一些帮助来检查代码. [英] How to use DateDiff calculation around textboxes? Need some help to check code.

查看:76
本文介绍了如何在文本框周围使用DateDiff计算?需要一些帮助来检查代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello CodeProject,

我正在将访问数据库迁移到vb.net.
我的员工数据库中有一些DateTimePickers,文本框和组合框.
在访问中,我在文本框的控制源中有这样的公式,并且可以正常工作:

Hello CodeProject,

I`m migrating access database to vb.net.
I have employee database with a few DateTimePickers, textboxes, and comboboxes.
In access I have formulas in textbox''s control source like this, and it works:

txtDayCalculation
=DateDiff("d",txtDateofHire, txtManualDate)
txtYear
=Int(txtDayCalculation/365)
txtMonth
=Int((txtDayCalculation-(txtYear*365))/30) 
txtDay
=((txtDayCalculation-txtYear*365))-(txtMonth*30)



因此,我也尝试在vb.net中这样做,但未成功.
也许我编写代码的方法是错误的.

无论如何,我有这样的代码:



So, I have trying to do also in vb.net, but NOT successful.
Maybe my approach to write a code is wrong.

Anyway, I have code like this:

me.txtDayCalculation.text = DateDiff("d",txtDateOfHireDateTimePicker, txtManualDateDateTimePicker)



请有人检查代码,并给我更正.
在此先感谢您对任何人的帮助



Please someone to check code, and give me corrections.
Thank you in advance for help to anyone

推荐答案

在底部阅读本文是一个很好的例子,展示您的后见之物

MSDN:datediff函数 [
read this article at the bottom is a great example showing what your after

MSDN : datediff function[^]


尝试使用时间跨度 [ ^ ]对象.


如果您需要获取两天之间的天数,只需使用以下代码即可:

If you need to get the number of days between the two days, you can simply use this:

int daysDifference = (datePicker1.Value - datePicker2.Value).Days;



这将给出几天的总数.如果需要专家编号,请使用TotalDays代替Days.



This will give the whole number for days. If you need excat number, use TotalDays instead of Days.


这篇关于如何在文本框周围使用DateDiff计算?需要一些帮助来检查代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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