Solved

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

Posted on 2014-02-23
3
1,828 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

The problems with reply email signatures

Do you wish that you could place an email signature under a reply? Well, unfortunately, you can't. That great Exchange/Office 365 signature you've created will just appear at the bottom of an email chain. What a pain! Is there really no way to solve this? Well, there might be...

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
A procedure for exporting installed hotfix details of remote computers using powershell
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 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

19 Experts available now in Live!

Get 1:1 Help Now