![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | date formatting I'm building a PowerShell script for ntbackup, starting with the date: $today = get-date Monday, March 31, 2008 7:48:58 PM then the day of the week: $day_of_week = $today.dayofweek Monday then the output file name: $name_tag = get-date -uformat "%a" $backup_bkf = get-date -uformat "%Y-%m-%d-$name_tag.bkf" 2008-03-31-Mon.bkf But I really wanted to use the same time/date stamp value throughout. Instead of this: $backup_bkf = get-date -uformat "%Y-%m-%d-$name_tag.bkf" How can I do this: $backup_bkf = $today -uformat "%Y-%m-%d-$name_tag.bkf" -- Rob Pettrey Microsoft Small Business Specialist |
My System Specs![]() |
| | #2 (permalink) |
| | Re: date formatting $today = get-date # multiple assignment $day_of_Week, $name_tag = "$('{0:dddd},{0:ddd}' -f $today)".split(',') $day_of_Week $name_tag # string concatenation $backup_bkf = $($today.toString('yyyy-MM-dd')) + "-$name_tag.bkf" $backup_bkf # subexpression string expansion $backup_bkf = "$($($today.toString('yyyy-MM-dd')))-$name_tag.bkf" $backup_bkf # safer subexpression string expansion - note the curly braces $backup_bkf = "$($($today.toString('yyyy-MM-dd')))-${name_tag}.bkf" $backup_bkf # # # # # other samples w/o $name_tag $today = get-date $backup_bkf = '{0:yyyy-MM-dd-ddd}.bkf' -f $today $backup_bkf $today = get-date $backup_bkf = "$($today.toString('yyyy-MM-dd-ddd')).bkf" $backup_bkf -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| | Re: date formatting Excuse the typo, no subexpression needed: # string concatenation $backup_bkf = $today.toString('yyyy-MM-dd') + "-$name_tag.bkf" $backup_bkf -- Kiron |
My System Specs![]() |
| | #4 (permalink) |
| | Re: date formatting $today = get-date # multiple assignment $day_of_Week, $name_tag = "$('{0:dddd},{0:ddd}' -f $today)".split(',') $day_of_Week $name_tag # string concatenation $backup_bkf = $today.toString('yyyy-MM-dd') + "-$name_tag.bkf" $backup_bkf # subexpression string expansion $backup_bkf = "$($today.toString('yyyy-MM-dd'))-$name_tag.bkf" $backup_bkf # safer subexpression string expansion - note the curly braces $backup_bkf = "$($today.toString('yyyy-MM-dd'))-${name_tag}.bkf" $backup_bkf # other samples $today = get-date $backup_bkf = '{0:yyyy-MM-dd-ddd}.bkf' -f $today $backup_bkf $today = get-date $backup_bkf = "$($today.toString('yyyy-MM-dd-ddd')).bkf" $backup_bkf -- Kiron |
My System Specs![]() |
| | #5 (permalink) |
| | Re: date formatting Kiron, Perfect! Just what I needed! I ended up with: $backup_bkf = $today.toString('yyyy-MM-dd') + "-$name_tag.bkf" since it seemed the most intuitive to me. thanks again for the many examples! Very helpful! -- Rob Pettrey Microsoft Small Business Specialist "Kiron" wrote: Quote: > $today = get-date > > # multiple assignment > $day_of_Week, $name_tag = "$('{0:dddd},{0:ddd}' -f $today)".split(',') > $day_of_Week > $name_tag > > # string concatenation > $backup_bkf = $today.toString('yyyy-MM-dd') + "-$name_tag.bkf" > $backup_bkf > > # subexpression string expansion > $backup_bkf = "$($today.toString('yyyy-MM-dd'))-$name_tag.bkf" > $backup_bkf > > # safer subexpression string expansion - note the curly braces > $backup_bkf = "$($today.toString('yyyy-MM-dd'))-${name_tag}.bkf" > $backup_bkf > > # other samples > $today = get-date > $backup_bkf = '{0:yyyy-MM-dd-ddd}.bkf' -f $today > $backup_bkf > > $today = get-date > $backup_bkf = "$($today.toString('yyyy-MM-dd-ddd')).bkf" > $backup_bkf > > > -- > Kiron > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| date time formatting | .NET General | |||
| Modified Date used as Date Taken in Photo Gallery and Digital Imag | Vista music pictures video | |||
| Photo date taken vs. file date | Vista music pictures video | |||
| Problem formatting date | PowerShell | |||
| Blank "Date Taken / Date Modified" field in Vista | Vista file management | |||