如何将分钟转换为DateTime / DateTime分钟 [英] How to convert minutes to DateTime / DateTime to minute

查看:135
本文介绍了如何将分钟转换为DateTime / DateTime分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一个问题:我必须转换110分钟到时间格式意味着01:50:00(hh:mi:ss)。

如何做到这一点。?



我的第二个问题:我已将日期转换为分钟。但在这种情况下,我无法将秒转换为分钟并将其添加到分钟。

我的计算是这里:

i有日期:1/9/2012 1:30:12 AM

兑换分钟回报:90



my first problem : i have to convert 110 minute into time format means 01:50:00 (hh:mi:ss).
how to do this.?

my second problem : i have convert date to minute.But in that case i cant able to convert second into minute and add it to minute.
my calculation is here:
i have date : 1/9/2012 1:30:12AM
convert to minute returns : 90

SELECT     name1, address, mob, city, emailid,(datepart(hh,[date]) * 60) + datepart(n, [date]) + (datepart(ss,[date])/60)
FROM         [user.]

推荐答案

将[YourInput]替换为你的时间


replace [YourInput] to your time in minuted

Select CAST(([YourInput] / 60) as varchar(2)) + ':' + CAST(([YourInput] % 60) as varchar(2))





函数可以是从以下位置找到



http://stackoverflow.com/questions/2944580/minutes-to-time-in-sql-server [ ^ ]


new System.TimeSpan ( 0 , 150 , 0 ).ToString()







System.DateTime d = System.DateTime.Parse ( "1/9/2012 1:30:12" ) ;
double minutes = d.TimeOfDay.TotalMinutes ;





这产生90.2 - 您对小数部分的处理方式是给你;圆形,天花板,地板等



如果您希望SQL将秒数添加为部分分钟,则可以更改第二个 60 60.0 - 那么你应该得到90.2好了。



This yields 90.2 -- what you do with the fractional part is up to you; Round, Ceiling, Floor, etc.

And if you want your SQL to add the seconds as partial minutes, you can change the second 60 to 60.0 -- you should then get 90.2 there are well.


这篇关于如何将分钟转换为DateTime / DateTime分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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