![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Add Date and time to filename How do I add the date and time onto a filename I am generating in format somefilename20070511-0911 ? Thanks |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Add Date and time to filename if... $d = get-date then... $d.year() + $d.month() + $d.day() + "-" $d.hour + $d.minute Or something along those lines - use the methods of the datetime object to get just the bits you want. You can also run $d.GetDateTimeFormats() to see if one of the predefined string formats will work for you. -- Don Jones Windows PowerShell MVP Founder: www.ScriptingAnswers.com Co-Author: "Windows PowerShell: TFM" "Jimbo" <Jimbo@discussions.microsoft.com> wrote in message news:333EB1A8-E981-4882-BA24-35D13000DA4E@microsoft.com... > How do I add the date and time onto a filename I am generating in format > somefilename20070511-0911 ? > > Thanks |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Add Date and time to filename The more I play with the format operator ( -f ) the more I love it. You can generate your filename like this: PS> $date = Get-Date PS> $filename PS> $filename = "FileName{0}{1:d2}{2:d2}-{3:d2}{4:d2}" -f $date.year,$date.month,$date.day,$date.hour,$date.minute PS> $FileName FileName20070511-1035 "get-help about_operators" has a little bit on the subject. ^_^ ~Clint $filename = "FileName{0}{1:d2}{2:d2}-{3:d2}{4:d2}" -f $date.year,$date.month,$date.day,$date.hour,$date.minute "Jimbo" <Jimbo@discussions.microsoft.com> wrote in message news:333EB1A8-E981-4882-BA24-35D13000DA4E@microsoft.com... > How do I add the date and time onto a filename I am generating in format > somefilename20070511-0911 ? > > Thanks |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Add Date and time to filename Hi Clint, > The more I play with the format operator ( -f ) the more I love it. You can generate your filename like this: > > PS> $date = Get-Date > PS> $filename > PS> $filename = "FileName{0}{1:d2}{2:d2}-{3:d2}{4:d2}" -f $date.year,$date.month,$date.day,$date.hour,$date.minute Or just write it like that: PS> $filename = "FileName{0:yyyyMMdd-HHmm}" -f (Get-Date) hth Max |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Add Date and time to filename That is fantastic. (^_^) "Maximilian Hänel" <ngSpam@smjh.de> wrote in message news:eo8O3x$kHHA.4848@TK2MSFTNGP05.phx.gbl... > Hi Clint, > >> The more I play with the format operator ( -f ) the more I love it. You can generate your filename like this: >> >> PS> $date = Get-Date >> PS> $filename >> PS> $filename = "FileName{0}{1:d2}{2:d2}-{3:d2}{4:d2}" -f $date.year,$date.month,$date.day,$date.hour,$date.minute > > Or just write it like that: > > PS> $filename = "FileName{0:yyyyMMdd-HHmm}" -f (Get-Date) > > hth > > Max |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| ren filename with time help | PowerShell | |||
| get-date - make it a filename | PowerShell | |||
| Date and Time slowing down | Vista performance & maintenance | |||
| Date and Time | Vista General | |||
| Date and Time | Tutorials | |||