如何从日期时间选择器值中获取小时和分钟的差异 [英] How to get the difference of hours and minutes from datetime picker values

查看:103
本文介绍了如何从日期时间选择器值中获取小时和分钟的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经开发了一个桌面应用程序,其中我已经从访问数据库中获取数据,即与日期时间选择器值之间的小时和分钟的差异,为此,我在下面编写了代码,但我没有得到分钟数的差异.

Hi Everyone,

I have developed a desktop application in which i have fetch data from access database i.e difference of hours and minutes from datetime picker values, to get this i have written the code below but I am not getting the minutes difference.

mStrFinalQuery = "select VehicleMaster.RegistrationNo,VehicleTransaction.Barcode,VehicleMaster.VehicleType,VehicleMaster.VehicleModel,format(VehicleTransaction.TranInDate,""dd-MM-yyyy HH:mm:ss"") as InDate,format(VehicleTransaction.TranOutDate,""dd-MM-yyyy HH:mm:ss"") as OutDate,format(TranInDate,""HH"")-format(TranOutDate,""HH"") AS TotalOutHour,format(TranInDate,""mm"")-format(TranOutDate,""mm"") AS TotalMins from VehicleMaster inner join VehicleTransaction on VehicleMaster.Barcode = VehicleTransaction.Barcode where TranDate>= format('" & DateTimePicker1.Text & "',""dd-MM-yyyy"") and TranDate<= format('" & DateTimePicker2.Text & "',""dd-MM-yyyy"") order by TransactionId"



谢谢您的帮助.



Any help is kindly appreciated

推荐答案

由于您通过传递日期时将其格式化的方式浪费了DateTimePicker的时间部分,因此无济于事,但是随后您将一个很好的日期时间值转换为字符串,以便从中减去另一个字符串!

使用 DateDiff函数 [
Since you are throwing away the time portion of the DateTimePicker by formatting it when you pass it through, that isn''t going to help, but then you convert a perfectly good date time value to a string in order to subtract another string from it!

Use the DateDiff function[^] instead...

And pass your values as DateTime via a parametrised query rather than converting them to a string in the first place!


这篇关于如何从日期时间选择器值中获取小时和分钟的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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