日期:2014-05-17 浏览次数:20596 次
DECLARE @dt DATETIME
SET @dt=CONVERT(VARCHAR(10),GETDATE(),120)
;WITH temp AS (
SELECT
[Datatime]=DATEADD(mi,number,@dt),
[openDatatime]=CASE
WHEN CONVERT(VARCHAR(5),DATEADD(mi,number,@dt),114) BETWEEN '00:00' AND '01:55' THEN DATEADD(mi,(number/5+1)*5,@dt)
WHEN CONVERT(VARCHAR(5),DATEADD(mi,number,@dt),114) BETWEEN '10:00' AND '21:50' THEN DATEADD(mi,(number/10+1)*10,@dt)
WHEN CONVERT(VARCHAR(5),DATEADD(mi,number,@dt),114) BETWEEN '22:00' AND '23:55' THEN DATEADD(mi,(number/5+1)*5,@dt)
ELSE null
END
FROM [master].dbo.spt_values sv WHERE sv.[type]='p' AND DATEADD(mi,number,@dt)<DATEADD(dd,1,@dt)
)
SELECT
时间=CONVERT(VARCHAR(5),[Datatime],114),
相差秒=DATEDIFF(ss,[Datatime],[openDatatime])
FROM temp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var data = Enumerable.Range(0, 24 * 60)
.Select(x => new { H = x / 60, M = x % 60, X = x })
.Where(x => x.M % 5 == 0)
.Where(x => x.H < 2