Get‑SqlDscDateTime - dsccommunity/SqlServerDsc GitHub Wiki
Retrieves the current date and time from a SQL Server instance.
Get-SqlDscDateTime [-ServerObject] <Server> [[-DateTimeFunction] <String>] [[-StatementTimeout] <Int32>]
[<CommonParameters>]
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.
$serverObject = Connect-SqlDscDatabaseEngine
Get-SqlDscDateTime -ServerObject $serverObject
Connects to the default instance and retrieves the current date and time using the default SYSDATETIME function.
$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.
$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.
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: FalseSpecifies 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: FalseSpecifies 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: FalseThis cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.