![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Convert a string to date/time format I've looked at various threads and tried various suggestions I have a string: $str = "Apr 23 14:16" I would like to convert this into a date time format variable so I can perform a get-date and compare the two i.e. if string is -gt 3minutes older than get-date then do something Any help would be greatly appreciated Many Thanks -- jobbsy@xxxxxx |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Convert a string to date/time format you can use ParseExact static method for DateTime: $str = "Apr 23 14:16" [datetime]::ParseExact($str, "MMM dd HH:mm", $null) MMM - month in string format dd - day HH - time in 24h format (hh - in 12h format with AM/PM appendix) mm - minutes. enjoy! -- WBR, Vadims Podans MVP: PowerShell PowerShell blog - www.sysadmins.lv "Jobbsy" <Jobbsy@xxxxxx> rakstīja ziņojumā "news:57FADB60-70C1-4D73-B89B-FFDFC3E845FD@xxxxxx"... Quote: > I've looked at various threads and tried various suggestions > > I have a string: > > $str = "Apr 23 14:16" > I would like to convert this into a date time format variable so I can > perform a get-date and compare the two > > i.e. if string is -gt 3minutes older than get-date then do something > > Any help would be greatly appreciated > > Many Thanks > -- > jobbsy@xxxxxx |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Convert a string to date/time format mm, I forget second part of your task. $str = "Apr 23 14:16" if ((Get-date).AddMinutes(-3) -gt ([datetime]::ParseExact($str, "MMM dd HH:mm", $null))) {"do something"} have a nice day! -- WBR, Vadims Podans MVP: PowerShell PowerShell blog - www.sysadmins.lv "Vadims Podans [MVP]" <vpodans> rakstīja ziņojumā "news:#RqczMDxJHA.4476@xxxxxx"... Quote: > you can use ParseExact static method for DateTime: > > $str = "Apr 23 14:16" > [datetime]::ParseExact($str, "MMM dd HH:mm", $null) > MMM - month in string format > dd - day > HH - time in 24h format (hh - in 12h format with AM/PM appendix) > mm - minutes. > > enjoy! > -- > WBR, Vadims Podans > MVP: PowerShell > PowerShell blog - www.sysadmins.lv > > "Jobbsy" <Jobbsy@xxxxxx> rakstīja ziņojumā > "news:57FADB60-70C1-4D73-B89B-FFDFC3E845FD@xxxxxx"... Quote: >> I've looked at various threads and tried various suggestions >> >> I have a string: >> >> $str = "Apr 23 14:16" >> I would like to convert this into a date time format variable so I can >> perform a get-date and compare the two >> >> i.e. if string is -gt 3minutes older than get-date then do something >> >> Any help would be greatly appreciated >> >> Many Thanks >> -- >> jobbsy@xxxxxx |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| RE: How to convert Table-Format Data to CSV-Format? | PowerShell | |||
| RE: How to convert Table-Format Data to CSV-Format? | PowerShell | |||
| Birthday field date and time format | Vista mail | |||
| Converting date time format to string format | PowerShell | |||
| Photo Gallery Date/Time Format | Vista file management | |||