Skip to content

Get‑SqlDscDateTime

dscbot edited this page Dec 14, 2025 · 1 revision

SYNOPSIS

Retrieves the current date and time from a SQL Server instance.

SYNTAX

Get-SqlDscDateTime [-ServerObject] <Server> [[-DateTimeFunction] <String>] [[-StatementTimeout] <Int32>]
 [<CommonParameters>]

DESCRIPTION

Retrieves the current date and time from a SQL Server instance using the specified T-SQL date/time function. This command helps eliminate clock-skew and timezone issues when coordinating time-sensitive operations between the client and SQL Server.

The command queries SQL Server using the server connection context, which does not require any database to be online.

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine
Get-SqlDscDateTime -ServerObject $serverObject

Connects to the default instance and retrieves the current date and time using the default SYSDATETIME function.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine
$serverObject | Get-SqlDscDateTime -DateTimeFunction 'SYSUTCDATETIME'

Connects to the default instance and retrieves the current UTC date and time from the SQL Server instance.

EXAMPLE 3

$serverObject = Connect-SqlDscDatabaseEngine
$serverTime = Get-SqlDscDateTime -ServerObject $serverObject
Restore-SqlDscDatabase -ServerObject $serverObject -Name 'MyDatabase' -StopAt $serverTime.AddHours(-1)

Demonstrates using the server's clock for a point-in-time restore operation, avoiding clock skew issues between client and server.

PARAMETERS

-DateTimeFunction

Specifies which T-SQL date/time function to use for retrieving the date and time. Valid values are:

  • SYSDATETIME (default): Returns datetime2(7) with server local time
  • SYSDATETIMEOFFSET: Returns datetimeoffset(7) with server local time and timezone offset
  • SYSUTCDATETIME: Returns datetime2(7) with UTC time
  • GETDATE: Returns datetime with server local time
  • GETUTCDATE: Returns datetime with UTC time
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: SYSDATETIME
Accept pipeline input: False
Accept wildcard characters: False

-ServerObject

Specifies current server connection object.

Type: Server
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-StatementTimeout

Specifies the query StatementTimeout in seconds. Default 600 seconds (10 minutes).

Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: 600
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

Microsoft.SqlServer.Management.Smo.Server

Accepts input via the pipeline.

OUTPUTS

System.DateTime

Returns the current date and time from the SQL Server instance.

NOTES

RELATED LINKS

Home

Commands

How-to

Resources

Usage

Clone this wiki locally