![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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) |
| Guest | 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) |
| Guest | 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) |
| Guest | 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) |
| Guest | 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 | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| date time formatting | Andrew | .NET General | 4 | 07-09-2008 12:18 AM |
| Date time calculations | Snowmizer | PowerShell | 11 | 04-18-2008 07:04 PM |
| Date and Time - Change | Brink | Tutorials | 0 | 12-19-2007 03:28 PM |
| Date and Time | inkd4life | Vista General | 6 | 10-07-2007 02:04 AM |
| Date and Time | Brink | Tutorials | 0 | 06-24-2007 07:46 AM |