formatting date time value

Welcome Forums General PowerShell Q&A formatting date time value

  • This topic has 2 replies, 2 voices, and was last updated 1 month ago by
    Participant
    .
Viewing 1 reply thread
  • Author
    Posts
    • #279819
      Participant
      Topics: 29
      Replies: 46
      Points: 434
      Rank: Contributor

      hi all,

      given that $diff = this;

      Days : 0
      Hours : 1
      Minutes : 44
      Seconds : 29
      Milliseconds : 429
      Ticks : 62694298389
      TotalDays : 0.0725628453576389
      TotalHours : 1.74150828858333
      TotalMinutes : 104.490497315
      TotalSeconds : 6269.4298389
      TotalMilliseconds : 6269429.8389

      when I try to display the time in the following format, the values are empty. i can’t understand why.

      $diff = (Get-Date) – $time
      $stringToWrite = “{0:hh}:{1:mm}:{2:ss}” -f ($diff.hours), ($diff.minutes), ($diff.seconds)
      $stringToWrite

      hh:mm:ss

      thanks!

    • #279840
      Participant
      Topics: 9
      Replies: 707
      Points: 2,842
      Helping Hand
      Rank: Community Hero

      You’re trying to extract hours, minutes, and seconds out of raw numbers. Do this instead

      • #279861
        Participant
        Topics: 29
        Replies: 46
        Points: 434
        Rank: Contributor

        that was too easy 😉

        with the explanation, i now understand what i did wrong.

        thank you!

Viewing 1 reply thread
  • You must be logged in to reply to this topic.