Sunteți pe pagina 1din 3

Add Date and time to filename - Vista Forums

1 of 3

http://www.vistax64.com/powershell/62763-add-date-time-filename.html

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.

User Name User Name

Vista Forums > Vista Newsgroup Archive > Misc Newsgroups > PowerShell

Add Date and time to filename


Join Now

Password
FAQ

Today's Posts

Remember Me?
Log in

Search

Vista - Add Date and time to filename


Recommended: Click here to Fix Errors & Optimize Windows

#1 (permalink)

11 May 2007

Jimbo
Add Date and time to filename
n/a posts

How do I add the date and time onto a filename I am generating in format
somefilename20070511-0911 ?

.VBS scripts Editor Award-winning editor for WSH Includes a built-in debugger ! www.vbsedit.com
Free RMM Software Get #1 remote management software Free for one year - a 1200$ value! N-able.com/OneYearFreeOffer

Thanks
My System Specs
11 May 2007

#2 (permalink)

Don Jones [MVP]


Re: Add Date and time to filename
n/a posts

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
11 May 2007

#3 (permalink)

16-12-2012 14:23

Add Date and time to filename - Vista Forums

2 of 3

http://www.vistax64.com/powershell/62763-add-date-time-filename.html

Clint Bergman
Re: Add Date and time to filename
n/a posts

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-4882BA24-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)

11 May 2007

Maximilian Hnel
Re: Add Date and time to filename
n/a posts

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
11 May 2007

#5 (permalink)

Clint Bergman
Re: Add Date and time to filename
n/a posts

That is fantastic.
(^_^)
"Maximilian Hnel" <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
>

16-12-2012 14:23

Add Date and time to filename - Vista Forums

3 of 3

http://www.vistax64.com/powershell/62763-add-date-time-filename.html

> Max

My System Specs

Add Date and time to filename problems?

Win32_Share | How can you remotely instantiate a WMI class?

Similar topics to: Add Date and time to filename


Thread

Forum

Date and Time

Tutorials

live mail how do I insert time and date into message --- all -- everymessage a ez way to automatically insert time and date into
live message

Live Mail

How to Sort on Date in Filename?

VB Script

ren filename with time help

PowerShell

get-date - make it a filename

PowerShell

Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
Designer Media Ltd
Contact Us - Windows 7 Help and support - Windows 8 Forums - Archive - Privacy and cookies - Legal - Top

16-12-2012 14:23

S-ar putea să vă placă și