[英]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.