Gepostet am: Nov 20, 2012 10:3:28 AM
Es gibt im Microsoft SQL-Server (T-SQL) 3 Arten, das aktuelle Datum samt Zeit zu erhalten.
CURRENT_TIMESTAMP, GETDATE() und {fn NOW()}
Folgende Beispiele liefern allesamt den aktuellen Zeitstempel. Es gibt zwischen den Methoden auch keinen Geschwindigkeitsunterschied.
SELECT CURRENT_TIMESTAMP
SELECT {fn NOW()}
SELECT GETDATE()
Untenstehende Beispiele zeigen, wie man das aktuelle Jahr (das Jahr von "heute") erhält.
Methode 1:
CURRENT_TIMESTAMP
CURRENT_TIMESTAMP is a nondeterministic function. Views and expressions that reference this column cannot be indexed. CURRENT_TIMESTAMP can be used to print the current date and time every time that the report is produced.
Beispiel: select year(current_timestamp) ... liefert das aktuelle Jahr
Methode 2:
GETDATE()
GETDATE is a nondeterministic function. Views and expressions that reference this column cannot be indexed. GETDATE can be used to print the current date and time every time that the report is produced.
Beispiel: select year(getdate()) ... liefert das aktuelle Jahr
Methode 3:
{fn Now()}
The {fn Now()} is an ODBC canonical function which can be used in T-SQL since the OLE DB provider for SQL Server supports them. {fn Now()} can be used to print the current date and time every time that the report is produced.
Beispiel: select year({fn Now()}) ... liefert das aktuelle Jahr