Get-KFDateTime

Syntax

Get-KFDateTime
  -Dt <system.datetime>
  -DtUtc <system.datetime>
  [-Real[:$false]]
  [-UTC[:$false]]
  [-DateOnly[:$false]]
  [-AsString[:$false]]
  [-IncludeSeconds[:$false]]
  [-IncludeTime[:$false]]
  [-Format <format-string>]
  [-ThrowErrors[:$false]]

Support

>= kenaflow 1.0.0

Return

DateTime or String.

Description

This is a tool cmdlet intended to use for debugging and for production.

Together with Get-KFDateTime and Set-KFDateTime this cmdlet can be used to simulate time differences in a debugging context. First you set a time difference with Set-KFDateTime that is relative to the current time. When you get the time using Get-KFDateTime the difference is added or substracted from the current time. In combination with Get-KFInDebug you can simulate a workflow run "later" or "earlier", e.g. if you check time stamps against the current time.

With -Dt <datetime> or -DtUtc <datetime> you can specify a custom DateTime. If non is specified DateTime.Now is used. If both are specified the value of -Dt is used and -DtUtc is ignored.

When you specify -Real the previously with Set-KFDateTime set time difference is not used.

When you specify the parameter -UTC the value of -Dt (or -DtUtc) is converted to Utc.

When you specify the parameter -DateOnly the time part is removed.

When a time difference was set with Set-KFDateTime (and not cleared with Clear-KFDateTime) the time difference is added to the DateTime.

When -AsString is not specified the calculated DateTime is now returned by the cmdlet.

When -AsString is specified the calculated DateTime is now converted to a string.

If no -Format is specified following formats are used:

  • If -DateOnly if specified: yyyy-MM-dd is used OR
  • If hour, minute and seconds of the calculated DateTime are all "0" and -IncludeTime is not specified: yyyy-MM-dd is used OR
  • If -IncludeTime is specified but not -IncludeSeconds: yyyy-MM-dd HH:mm is used OR
  • If -IncludeTime and -IncludeSeconds are specified: yyyy-MM-dd HH:mm:ss is used

Sounds complicated? In SharePoint the "DateOnly" field contains a complete DateTime but with hour == 0, minute == 0 and second == 0.

Therefore when using -AsString without other parameters you get only the date part for a DateTime with hour == 0, minute == 0, second == 0. But with hour and minute in the returned string for DateTime values with hour != 0, minute != 0 and/or second != 0.

Parameters

-Dt <system.datetime>

DateTime to be processed. Default is $null.

-DtUtc <system.datetime>

DateTime to be processed. Default is $null.

[-Real[:$false]]

If set: continue processing with the real DateTime. Do not add the set time difference.

[-UTC[:$false]]

Handle the currently processed DateTime as UTC.

[-DateOnly[:$false]]

Continue only with the "date" part of the DateTime.

[-AsString[:$false]]

Return the DateTime as string.

[-IncludeSeconds[:$false]]

Include Seconds in the returned string. (If -IncludeTime is used and -DateOnly is not used.)

[-IncludeTime[:$false]]

Include the time part of the DateTime in the returned string (if -DateOnly is not used). It's used to force also hour == 0, minute == 0 and second == 0 to be included.

[-Format <format-string>]

A custom DateTime format. If specified the settings -DateOnly, -IncludeTime and -IncludeSeconds are ignored.

[-ThrowErrors[:$false]]

This is a default parameter for all kenaflow cmdlets. If set to $true (default!) the engine will pass exception within the cmdlet to the script for further handling.

Example

Set-KFDateTime -ReferenceDateTime  ([DateTime]"1900-01-01 12:00:00")
Start-Sleep -Seconds 5
Get-KFDateTime -AsString -Format "yyyy-MM-dd HH:mm:ss" 

This will return 1900-01-01 12:00:05.

Discussion