提问者:小点点

如何更改time_format以便我也可以将它与Date一起使用


我想在我的报告日期+时间,但我不知道如何替换time_format,以获得日期也在那里。 time_format(T1.日期,“%d/%m/%y-%h:%i:%s”)

create VIEW `test`  AS 
with cte as (select `entries`.`emp_id` AS `emp_id`,`entries`.`Date` AS `Date`,
row_number() over ( partition by `entries`.`emp_id` order by `entries`.`Date`) - 1 AS `rn` 
from `entries`)select `user`.`Name` AS `name`,
time_format( `t1`.`Date`,'%H:%i:%s') AS `IN`,time_format(`t2`.`Date`,'%H:%i:%s') AS `OUT`,
timediff(`t2`.`Date`,`t1`.`Date`) AS `Work Time` from ((`user` join `cte` `t1` on(`user`.`emp_id` = `t1`.`emp_id`)) 
left join (select `entries`.`emp_id` AS `emp_id`,`entries`.`Date` AS `Date`,
row_number() 
over ( partition by `entries`.`emp_id` order by `entries`.`Date`) - 1 AS `rn` from `entries`) `t2` 
on(`t1`.`emp_id` = `t2`.`emp_id` and `t1`.`rn` DIV 2 = `t2`.`rn` DIV 2 and `t2`.`rn` MOD 2)) 
where !(`t1`.`rn` MOD 2) order by date_format(`t1`.`Date`,'%d/%M/%Y') ;

共1个答案

匿名用户

我想你问的是你有时间和日期,但你想把时间和日期结合在一起。 为此,您可以使用concat函数,然后将日期和时间连接在一起。 现在,一旦您有了一个同时包含日期和时间的字符串。 然后可以将该字符串强制转换为datetime数据类型。 我希望这个建议能有所帮助。