简体   繁体   English

在SQL中将时间格式从00:00:00更改为秒

[英]Change a time format from 00:00:00 into seconds in Sql

Within my ASP.Net application I have an Sql database. 在我的ASP.Net应用程序中,我有一个Sql数据库。 One of the columns in a table is called productDelivered which uses the data type time(7); 表中的一列称为productDelivered,它使用数据类型time(7); however, i would like to convert the time to seconds and keep it. 但是,我想将时间转换为秒并保留下来。 I have around 50-60 records. 我有大约50-60条记录。

Is there a way to change these times to seconds? 有没有办法将这些时间更改为秒? I dont mind creating a new column in the table for productDeliveredSeconds but I thought maybe a stored procedure or a view might do it? 我不介意在表中为productDeliveredSeconds创建新列,但我认为也许存储过程或视图可以做到这一点?

You can add a computed column to your table that uses datediff to calculate the number of seconds. 您可以在表中添加一个使用datediff来计算秒数的计算列

alter table YourTable add productDeliveredSeconds as datediff(second, 0, productDelivered)

Or you can use datediff in a query. 或者,您可以在查询中使用datediff

select datediff(second, 0, productDelivered) as productDeliveredSeconds 
from YourTable

TIME_TO_SEC(time) returns the time argument, converted to seconds. TIME_TO_SEC(time)返回时间参数,转换为秒。

mysql> SELECT TIME_TO_SEC('22:23:00');
        -> 80580
mysql> SELECT TIME_TO_SEC('00:39:38');
        -> 2378

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正则表达式为00:00时间格式> 24 - RegEx for 00:00 Time Format > 24 无法将日期时间格式剑道网格从 2022-12-12T00:00:00 更改为 12/12/2022 - can't change DateTime format kendo grid from 2022-12-12T00:00:00 to 12/12/2022 从asp文本框中删除00:00:00 - Remove 00:00:00 from the asp Textbox 从SQL日期格式读取日期会额外增加12:00:00 AM? - Reading date from sql date format adds extra 12:00:00 AM? 如何将行与时间格式(00:00:00)相加并在网格视图的页脚中生成? - How to sum of rows with time format(00:00:00) and produce in footer of Grid View? 如果不是时间为零,则使用DateTime格式删除时间(00:00:00) - DateTime formatting to remove time if not time is zero (00:00:00) 将javascript变量“11:00 AM”转换为c#等效,其中SQL是时间格式 - Convert javascript variable “11:00 AM” to c# equivalent where SQL is in time format 如何在GridView中使用数据字符串格式隐藏00:00时间跨度? - How to hide 00:00 timespan using data string format in gridview? 如何以00:00格式计算总工作时间? - How to calculate total working hour in 00:00 format? 更改 DateFormatString 以显示 11:59:59 而不是 12:00:00 - Change DateFormatString to show 11:59:59 as opposed to 12:00:00
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM