Date and Time Functions Flashcards

1
Q

Which functions return the current date and time?

A
  1. GETDATE
  2. CURRENT_TIMESTAMP
  3. GETUTCDATE
  4. SYSDATETIME
  5. SYSUTCDATETIME
  6. SYSDATETIMEOFFSET

SQL Server 70-461 02-02b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

GETDATE

A

Returns the current date and time in the SQL Server instance you are connected to with a data type of DATETIME.

Result Format
2012–09–30 14:10:13.813

SQL Server 70-461 02-02b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

CURRENT_TIMESTAMP

A

Returns the current date and time in the SQL Server instance you are connected to, same as GETDATE. However, CURRENT_TIMESTAMP is standard and GETDATE is specific to SQL Server so use CURRENT_TIMESTAMP.

Result Format
2012–09–30 14:10:13.813

SQL Server 70-461 02-02b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

GETUTCDATE

A

Returns the current date and timein the SQL Server instance you are connected to in UTC terms with a data type of DATETIME.

Result Format
2012–09–30 21:10:13.813

SQL Server 70-461 02-02b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

SYSDATETIME

A

Returns the current date and timein the SQL Server instance you are connected to with a data type of DATETIME2(7).

Result Format
2012–09–30 14:10:13.8160822

SQL Server 70-461 02-02b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

SYSUTCDATETIME

A

Returns the current date and timein the SQL Server instance you are connected to in UTC terms with a data type of DATETIME2(7).

Result Format
2012–09–30 21:10:13.8160822

SQL Server 70-461 02-02b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

SYSDATETIMEOFFSET

A

Returns the current date and timein the SQL Server instance you are connected to in UTC terms with a data type of DATETIMEOFFSET(7). The time zone offset is NOT adjusted for daylight savings time.

Result Format
2012–09–30 14:10:13.8160822 –07.00

SQL Server 70-461 02-02b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you return the current date OR current time but not both current date AND current time?

A

There are no built in functions for just the current date or just the current time. To accomplish this CAST the SYSDATETIME function to DATE or TIME. For example, CAST(SYSDATETIME() AS DATE).

SQL Server 70-461 02-02b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly