Querry-如何从日期时间格式获取日期 [英] Querry-How to get date from datetime format
问题描述
我想知道一个工作日的总小时数.
列是-
员工编号,开始日期,总小时数
一天中有不同时间的多个条目.
问题是开始日期的格式为-yyyy-mm-dd hh-mm-dd 000
并且用户在-dd-mm-yyyy中给出日期
我将此日期转换为convert(varchar,getdate(),111)它给出了yyyy-mm-dd格式
当我选择员工ID和开始日期时,我想要该特定日期的总工时总数.
谢谢
Hi, i want to know total numbers of hours in a working day.
columns are-
employeeid,startdate,totalhours
there are multiple entries on a single day with different time.
problem is that startdate is in format of- yyyy-mm-dd hh-mm-dd 000
and user is giving date in - dd-mm-yyyy
i am converting this date to convert(varchar,getdate(),111) it gives yyyy-mm-dd format
when i select employee id and startdate i want sum of totalhours of that particular date.
Thanks
推荐答案
尝试一次->
从表名组中按startDate,employeeid
选择employeeid,startdate,sum(totalhours)
它将显示雇员编号,开始日期和雇员在各个日期的总工作小时数.
Try this once-->
select employeeid,startdate,sum(totalhours) from tableName group by startDate,employeeid
it will display the employeeid,startdate and total no of hours employee worked on respective dates.
您好.....
试试这个,您将以hh:mm格式精确计算总小时数
hi there.....
try this, u will exact total hours in hh:mm format
SELECT employeeid,startdate,enddate,RIGHT('0' + CAST(DATEDIFF(HH,StartDate,EndDate) AS VARCHAR),2) + ':' +
RIGHT('0' + CAST(DATEDIFF(MI, StartDate,EndDate) % 60 AS VARCHAR),2) AS 'Total Hours'
FROM tableName
希望这对您有帮助...
回复您的评论...
hope this helps...
revert back with ur comments...
这篇关于Querry-如何从日期时间格式获取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!