Convert-TimeUnit.ps1


Description

Purpose

Converts a time value between seconds, minutes, hours, and days.

Detailed Description

Accepts a numeric value and converts it from one time unit to another.

Back to Top

Usage

Example 1

Convert-TimeUnit -Value 120 -From Seconds -To Minutes

Converts 120 seconds to minutes.

Example 2

Convert-TimeUnit -Value 2 -From Days -To Hours

Converts 2 days to hours.

Back to Top

Notes

Author: ChatGPT Date: 2025-06-01

Back to Top


Script

function Convert-TimeUnit {
    <#
    .SYNOPSIS
    Converts a time value between seconds, minutes, hours, and days.

    .DESCRIPTION
    Accepts a numeric value and converts it from one time unit to another.

    .PARAMETER Value
    The numeric time value to convert.

    .PARAMETER From
    The unit of the provided value. Supported units are Seconds, Minutes, Hours, and Days.

    .PARAMETER To
    The unit to convert the value into. Supported units are Seconds, Minutes, Hours, and Days.

    .EXAMPLE
    Convert-TimeUnit -Value 120 -From Seconds -To Minutes
    Converts 120 seconds to minutes.

    .EXAMPLE
    Convert-TimeUnit -Value 2 -From Days -To Hours
    Converts 2 days to hours.

    .NOTES
    Author: ChatGPT
    Date: 2025-06-01
    #>
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [double]$Value,

        [Parameter(Mandatory = $true)]
        [ValidateSet('Seconds','Minutes','Hours','Days')]
        [string]$From,

        [Parameter(Mandatory = $true)]
        [ValidateSet('Seconds','Minutes','Hours','Days')]
        [string]$To
    )

    $multipliers = @{
        Seconds = 1
        Minutes = 60
        Hours   = 3600
        Days    = 86400
    }

    ($Value * $multipliers[$From]) / $multipliers[$To]
}

Back to Top

Download

Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top