Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 622271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:58:01+00:00 2026-05-13T18:58:01+00:00

I can format the Get-Date cmdlet no problem like this: $date = Get-Date -format

  • 0

I can format the Get-Date cmdlet no problem like this:

$date = Get-Date -format "yyyyMMdd"

But once I’ve got a date in a variable, how do I format it? The statement below

$dateStr = $date -format "yyyMMdd"

returns this error:

“You must provide a value expression
on the right-hand side of the ‘-f’
operator”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:58:01+00:00Added an answer on May 13, 2026 at 6:58 pm

    The same as you would in .NET:

    $DateStr = $Date.ToString("yyyyMMdd")
    

    Or:

    $DateStr = '{0:yyyyMMdd}' -f $Date
    

    Note that you can have a format string that gets multiple objects. For example:

    'From {0:M/d/yyyy} to {1:M/d/yyyy}' -f $Date, $Date.AddDays(7)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody help me get this date format like Fri, 01 Oct 22:26:23 +0200
How can I get a date in a format like this out of Flash
Is there a way I can get a date by the format MM/dd but
In code like this, get '/posts.?:format?' do # ... end How can I get
I am working with DateTime, trying to get date in the format like this:
So I've got a text input that get's date & time in this format:
I can connect to server and get json data. it is in this format:
i get date from xml in this format: 7/16/2010 (mm/dd/yyyy) i have in my
Is there any way I can get datetime format like ' YYYY-MM-DD HH:MM:SS '
How can I format this date? <li>Sat Mar 03 2012 14:16:05 GMT+0530 (India Standard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.