如何在SQL Server中查询日期现在的值

时间:2017-03-03 08:11:10

标签: sql sql-server tsql

SELECT TOP 1000 
    TGL = CONVERT(DATE, TIMESTAMP), RIGHT('0' + CAST(DATEPART(hour, TimeStamp) AS VARCHAR(2)), 2) AS jam,
    Nilai = MAX(NILAI)
FROM 
    PLC_CPress2P1 
GROUP BY 
    CONVERT(DATE, TIMESTAMP), RIGHT('0' + CAST(DATEPART(hour, TimeStamp) AS VARCHAR(2)), 2)
ORDER BY 
    CONVERT(DATE, TIMESTAMP), RIGHT('0' + CAST(DATEPART(hour, TimeStamp) AS VARCHAR(2)), 2) DESC

我已尝试GATEDATE()NOW - 两者都无效

1 个答案:

答案 0 :(得分:2)

我认为你试图从日期等于今天的表格中选择一次?

在这种情况下,您可以这样做:

SELECT *columns*
FROM *table_name*
WHERE *specified_date_column* = CAST(GETDATE() as date)

在这里,您可以看到所有SQL Date函数:https://www.w3schools.com/sql/sql_dates.asp