如何使用2个约会结果显示日期之间的差异? [英] How do i display differences between dates using 2 datediff results?

查看:60
本文介绍了如何使用2个约会结果显示日期之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有没有人知道如何在2个不同的dtpicker中显示2次HH:mm而不仅仅是h或n?我正在为朋友设计一个项目,这样她就可以输入她的开始,结束和午餐时间,以计算每周工作总时数。


我确实有一个文本框输入方式,直到我意识到半小时是0.70!任何拯救这种方式的方式听起来都不错。



例如,我有15:00和17:15,我想要label1.caption来显示2小时15分钟。


除了明显的尝试,我尝试了以下但是15:00 17:00的答案是2.25


Dim minutesdiv,total1,time1hour,time2hour,total2,time1minute,time2minute,timediff As Variant


Private Sub Command1_Click()

time1hour = DTPicker1 。小时

time1minute = DTPicker1.Minute

time2hour = DTPicker2.Hour

time2minute = DTPicker2.Minute

total1 = time1hour& "。" &安培; time1minute

total2 = time2hour& "。" &安培; time2minute

timediff = DateDiff(" n",total1,total2)

minutesdiv = timediff / 60

Label1.Caption = minutesdiv


结束子


我使用变体,因为我是Vb的新手,如果我能够工作,我会适当改变。


我真的在这个小问题上花了大约12个小时。

解决方案





有没有人知道如何在2个不同的dtpicker显示HH:mm而不仅仅是h或n的结果中显示2次之间的差异?我正在为朋友设计一个项目,这样她就可以输入她的开始,结束和午餐时间,以计算每周工作总时数。


我确实有一个文本框输入方式,直到我意识到半小时是0.70!任何拯救这种方式的方式听起来都不错。


例如,我有15:00和17:15,我希望label1.caption显示2小时15分钟。


除了明显的尝试我尝试了以下但是15:00 17:00的答案是2.25


Dim minutesdiv,total1 ,time1hour,time2hour,total2,time1minute,time2minute,timediff As Variant

展开 | 选择 | Wrap | 行号


你不要知道我是多么放心它是有效的。


我现在可以去睡觉了! />

非常感谢,


Brendan


再次


上面给出的代码工作正常,除非我的朋友在23:00开始并在17:00结束,我知道这让我很困惑。那么这是否意味着我需要自定义dtpicker显示日期和时间?如果我需要定制怎么样?


它似乎变得复杂了,因为当我得到上面代码的答案时,我将不得不添加它们全部,按时间格式添加午餐金额,然后减去午餐时间总计。初步测试再次显示它会让人感到困惑。


当然人们在vb之前做过这种事情,我想做的就是添加开始时间,结束时间,多少每周的每一天的午餐,然后计算工作小时数。


任何方向都会得到很大的收获(我想自己做,我只需要轻推!)

Hi,

Does anyone know how to display differences between 2 times from 2 different dtpicker displaying results in HH:mm rather than just h or n? I am designing a project for friend so she can enter her start, end, and lunch time in order to calculate total weekly hours worked.

I did have a text box input way of doing until i realised that half an hour was 0.70! Any way of rescuing that way of doing it sounds good.



E.g, I have 15:00 and 17:15, I want label1.caption to display 2hrs 15mins.

Apart from the obvious attempts I have tried the following but the answer for 15:00 17:00 is 2.25

Dim minutesdiv, total1, time1hour, time2hour, total2, time1minute, time2minute, timediff As Variant


Private Sub Command1_Click()
time1hour = DTPicker1.Hour
time1minute = DTPicker1.Minute
time2hour = DTPicker2.Hour
time2minute = DTPicker2.Minute
total1 = time1hour & "." & time1minute
total2 = time2hour & "." & time2minute
timediff = DateDiff("n", total1, total2)
minutesdiv = timediff / 60
Label1.Caption = minutesdiv

End Sub

I have used variant as I am new to Vb, I would change appropriatly if I can get working.

I genuinely have spent about 12 hours on this small issue.

解决方案

Hi,

Does anyone know how to display differences between 2 times from 2 different dtpicker displaying results in HH:mm rather than just h or n? I am designing a project for friend so she can enter her start, end, and lunch time in order to calculate total weekly hours worked.

I did have a text box input way of doing until i realised that half an hour was 0.70! Any way of rescuing that way of doing it sounds good.


E.g, I have 15:00 and 17:15, I want label1.caption to display 2hrs 15mins.

Apart from the obvious attempts I have tried the following but the answer for 15:00 17:00 is 2.25

Dim minutesdiv, total1, time1hour, time2hour, total2, time1minute, time2minute, timediff As Variant

Expand|Select|Wrap|Line Numbers


You don''t know how relieved I am that it works.

I can go to sleep now!

Thank you so much,

Brendan


Hi again,

The code given above works fine unless my friend started at 23:00 and end at say 17:00, it''s getting confused I know. So does that mean I need to have custome dtpicker showing date as well as time? How would custom that if I need to?

It really seems to be getting complicated because when I get the answer to the above code, then I''m going to have to add them all up, add lunch amounts in time format and then subtract total of lunch times as well. Primary testing shows again it''ll get confused.

Surely People have done this kind of thing before on vb, all I Want to do is add start time, end time, how much for lunch for each day of week and then calculate amount of hours worked.

Any direction would be greatly received (I want to do it my self, I just need a nudge!)


这篇关于如何使用2个约会结果显示日期之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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