如何计算时间表中的小时数 [英] how to calculate time in hour in timesheet

查看:166
本文介绍了如何计算时间表中的小时数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好先生,

我有两个drpdown列表框。 dropdown1用于开始时间,dropdown2用于结束时间。

suppoce in dropdown1选择8:00 AM和Dropdown2选择08:30 AM我们如何计算时间并存储在数据库中。

谢谢你在高级

Hello Sir,
I have two drpdown list box. dropdown1 is for start time and dropdown2 is for end time.
suppoce in dropdown1 select 8:00AM and Dropdown2 select 08:30 AM how we calculate time and store in database.
Thankyou in Advanced

推荐答案

这不是很先进。



1.从中获取选定的值每个下拉框。



2.如果值是字符串,则需要将它们转换为数据类型DateTime,参见 DateTime.TryParse [ ^ ]



3.然后你减去两个DateTime变量。

结果将是 TimeSpan [ ^ ]。



4.将值存储在数据库的合适表格中

参见 SQL插入 [ ^ ]



5.您还需要数据库连接 [ ^ ]和SQL命令 [ ^ ]



我认为应该这样做。
This is not very advanced.

1. Get the selected values from each dropdown box.

2. If the values are strings, you need to convert them to the data type DateTime, see DateTime.TryParse[^]

3. Then you subtract the two DateTime variables.
The result will be an object of type TimeSpan[^].

4. Store the value in a suitable table in your database
See SQL Insert[^]

5. You will also need a database connection[^] and a SQL command[^]

That should do it, I think.


1。得到这样的时差 -

1. Get the time difference like this-
TimeSpan time1 = TimeSpan.Parse(dropdown1.SelectedItem); // can't recall the actual property to get the selected item text :laugh:
TimeSpan time2 = TimeSpan.Parse(dropdown2.SelectedItem);
TimeSpan difference = time1 - time2;
int hours = difference.Hours;
int minutes = difference.Minutes;





2。使用 SQL插入 [ ^ ]语句,用于在数据库中存储适当的值。请参阅此教程 [ ^ ]更多主意。





-KR



2. Use the SQL Insert[^] statement to store the appropriate value in database. Refer this tutorial[^] for more idea.


-KR


这篇关于如何计算时间表中的小时数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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