By using this site, you acknowledge that you have read and understand our Cookie policy, Privacy policy and Terms .

PowerShell provides a number of cmdlets to retrieve current date time and to create time span object.

Calculate time difference - CmdLets

$current = Get-Date

$end= Get-Date

$diff= New-TimeSpan -Start $current -End $end

Write-Output "Time difference is: $diff"

Output

image

The C# way

$current = [System.DateTime]::Now
$end= [System.DateTime]::Now
$diff= $end.Subtract($end)
Write-Output "Time difference is: $diff"

Output

image

info Last modified by Raymond at 3 years ago * This page is subject to Site terms.

More from Kontext

local_offer lite-log local_offer spark local_offer pyspark

visibility 2259
thumb_up 0
access_time 10 months ago

When creating Spark date frame using schemas, you may encounter errors about “field **: **Type can not accept object ** in type <class '*'>”. The actual error can vary, for instances, the following are some examples: field xxx: BooleanType can not accept object 100 in type ...

open_in_new View open_in_new Spark + PySpark

local_offer powershell

visibility 12
thumb_up 0
access_time 5 months ago

Environment variables are commonly used in many frameworks or programs.

open_in_new View open_in_new Code snippets

local_offer powershell

visibility 21
thumb_up 0
access_time 5 months ago

This code snippet shows how to calculate time differences.

open_in_new View open_in_new Code snippets

local_offer lite-log local_offer hive

visibility 1025
thumb_up 0
access_time 12 months ago

Since Hive 3.x, new authentication feature for HiveServer2 client is added. When starting HiveServer2 service (Hive version 3.0.0), you may encounter errors like: ‘HiveServer2 metastore.RetryingMetaStoreClient: RetryingMetaStoreClient trying reconnect as [username]  (auth:S...

open_in_new View open_in_new Hadoop

info About author

Kontext dark theme mode

Dark theme mode

Dark theme mode is available on Kontext.

Learn more arrow_forward
Kontext Column

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.

Learn more arrow_forward
info Follow us on Twitter to get the latest article updates. Follow us