如何在SQL中获取日期部分的最小日期

时间:2014-09-02 11:54:17

标签: sql select mindate

我想问一下如何从SQL Server DateTime查询中的Select列获取MIN DatePart。

这是我的疑问:

SELECT  
   MIN(CAST(DATEPART(DD, DateCreated) AS NVARCHAR) + 
   N'/' +
   CAST(DATEPART(MM, DateCreated) AS NVARCHAR) + 
   N'/' +
   CAST(DATEPART(YYYY, DateCreated) AS NVARCHAR)) AS DateFrom
FROM    
   [User]

结果应为04/04.2013,但现在结果为01/04/2014

请帮忙......

2 个答案:

答案 0 :(得分:1)

SELECT  MIN(CAST(DATEPART(DD,DateCreated) AS NVARCHAR) + 
        N'/' +
        CAST(DATEPART(MM,DateCreated) AS NVARCHAR) + 
        N'.' +
        CAST(DATEPART(YYYY,DateCreated) AS NVARCHAR)) AS DateFrom
FROM    [User]

答案 1 :(得分:0)

使用下面的聚合查询

select min(date) from tablename