Convert-DateToIso #
SYNOPSIS #
This PowerShell function converts a date to an ISO string. Source code on GitHub.
SYNTAX #
Convert-DateToIso [[-value] <DateTime>] [-asUtc] [-noTime] [-noDate] [-noTimeZone] [-zeroTime] [-noonTime]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
DESCRIPTION #
This function has several options to convert a date-time value combination into a string.
EXAMPLES #
Example 1:Local date in ISO format #
PS C:\> [string]$myDate= Convert-DateToIso -value $(Get-Date) -noTimeZone
PS C:\> $myDate
# Output
2023-02-17T13:29:02
Convert-DateToIso
takes the current date with time via the value parameter and outputs the date value in the local time.
PARAMETERS #
-asUtc #
The date is output in UTC, i.e. Greenwitch time. Here only a Z is appended to the output.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-noDate #
The date is suppressed or set to 1.1.1 for this output. However, only the time is output due to the formatting.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-noTime #
The time is suppressed for this output or set to 0:00. However, only the date is output due to the formatting.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-noTimeZone #
The date is output in local time without specifying the time zone.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-noonTime #
The time is ignored and set to 12 noon.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-value #
The value of the date/time combination to convert.
Type: DateTime
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-zeroTime #
The time is ignored and set to 0:00.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
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.