如何将分钟转换为DateTime / DateTime分钟

如何将分钟转换为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.