[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Get date in powershell in the format d.M.yyyy hh:mm AM/PM

Posted on 2014-02-23
3
Medium Priority
?
3,685 Views
Last Modified: 2014-02-23
I am trying to get the date in this format

(get-date).AddMinutes(10).ToString("d.M.yyyy hh:mm tt")

Where tt should be AM or PM. But I guess tt is wrong to use here.

All help appreciated.
0
Comment
Question by:itnifl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 1480 total points
ID: 39880737
Hi,
you need to pass a culture info - otherwise it could happen that you do not get the AM/PM (like on my computer where I have german settings):
$enus = 'en-US' -as [Globalization.CultureInfo]
(get-date).AddMinutes(10).ToString("d.M.yyyy hh:mm tt", $enus)

Open in new window

HTH
Rainer
1
 
LVL 83

Expert Comment

by:David Johnson, CD, MVP
ID: 39880838
Your Code is correct:

PS G:\Documents\WindowsPowerShell\Scripts> (get-date).addminutes(10).tostring("d.M.yyyy hh:mm tt")
23.2.2014 01:03 PM
PS G:\Documents\WindowsPowerShell\Scripts>

Open in new window

0
 
LVL 2

Author Comment

by:itnifl
ID: 39880845
David Johnson, CD, MVP:
But not on my system, most likely because I am not using a system with US local settings. I tested Rainer Jeschor solution, and it seems to work by setting these settings manually in the script.

But thank you anyway =)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question