Solved

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

Posted on 2014-02-23
3
1,987 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
3 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 370 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
0
 
LVL 78

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Synchronize a new Active Directory domain with an existing Office 365 tenant
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now