Solved

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

Posted on 2014-02-23
3
2,469 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
1
 
LVL 80

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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