formating date values

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

formating date values

Post by boyddt_co »

I'm working on a script (still) that pulls data from an xml file i've got it working and pushing the data to a file. The problem that I have now is that the date is "June 27, 2007" and I need "6/27/2007". I've tried -f and I get an error of not being able to format the screen. I've you need the exact error i can add that code and re-run. i've also tried to use [datevalue] on the string and i get this error: "make sure that the assembly containing this type is loaded."it seems as though get-date has a lot of features but formating a string doesn't.Thanx in advance.P.S. I do plan on getting a book this weekend.
User avatar
boyddt_co
Posts: 89
Last visit: Mon Sep 25, 2023 9:36 pm

formating date values

Post by boyddt_co »

I'm working on a script (still) that pulls data from an xml file i've got it working and pushing the data to a file. The problem that I have now is that the date is "June 27, 2007" and I need "6/27/2007". I've tried -f and I get an error of not being able to format the screen. I've you need the exact error i can add that code and re-run. i've also tried to use [datevalue] on the string and i get this error: "make sure that the assembly containing this type is loaded."it seems as though get-date has a lot of features but formating a string doesn't.Thanx in advance.P.S. I do plan on getting a book this weekend.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

formating date values

Post by jvierra »

$date=Get-Date
$date.toshortdatestring()

$d=[datetime]"7/05/1776"


jvierra2008-05-24 09:39:11
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

formating date values

Post by jhicks »

Define a variable at the beginning$dt=get-date -f yyyy-MM-ddHH:mmThen in your loop:$row.idtime=$dtIs that what you're after?
This topic is 15 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked