Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - How do I replace all characters in the "Now" date?

Reply
 
Old 10-28-2008   #1 (permalink)
Ed


 
 

How do I replace all characters in the "Now" date?

I'm trying to rename a file using all of the characters (including the
time) from the "Now" command, but I'm stuck.

This is very close (but it doesn't include the time, only the date):

Set objFSO = CreateObject("Scripting.FileSystemObject")
N=Now
strFNA = Right(Year(N),4) & "." & Right(100+Month(N),2) & "." &
Right(100+Day(N),2)
objFSO.MoveFile "testfile.txt", strFNA & ".txt"

All I want the filename to be is numeric digits and the extension.

Suggestions?

Thanks,
Ed

My System SpecsSystem Spec
Old 10-28-2008   #2 (permalink)
Evertjan.


 
 

Re: How do I replace all characters in the "Now" date?

Ed wrote on 28 okt 2008 in microsoft.public.scripting.vbscript:
Quote:

> I'm trying to rename a file using all of the characters (including the
> time) from the "Now" command, but I'm stuck.
>
> This is very close (but it doesn't include the time, only the date):
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> N=Now
> strFNA = Right(Year(N),4) & "." & Right(100+Month(N),2) & "." &
> Right(100+Day(N),2)
> objFSO.MoveFile "testfile.txt", strFNA & ".txt"
>
> All I want the filename to be is numeric digits and the extension.
strDateFile = year(N) & T(month(N),2) & T(day(N),2) &_
T(hour(N),2) & T(minute(N),2) & ".txt"

function T(s,n)
T = right("000"&s,n)
end function

not tested

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
My System SpecsSystem Spec
Old 10-28-2008   #3 (permalink)
Pegasus \(MVP\)


 
 

Re: How do I replace all characters in the "Now" date?


"Ed" <edflecko@xxxxxx> wrote in message
news:e2b6efe7-ebd9-4918-8d37-59ea07b3980d@xxxxxx
Quote:

> I'm trying to rename a file using all of the characters (including the
> time) from the "Now" command, but I'm stuck.
>
> This is very close (but it doesn't include the time, only the date):
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> N=Now
> strFNA = Right(Year(N),4) & "." & Right(100+Month(N),2) & "." &
> Right(100+Day(N),2)
> objFSO.MoveFile "testfile.txt", strFNA & ".txt"
>
> All I want the filename to be is numeric digits and the extension.
>
> Suggestions?
>
> Thanks,
> Ed
You could use a regular expression to extract the digits, e.g. like so:

Set oRegEx = CreateObject("VBScript.RegExp")
oRegEx.Global = True
oRegEx.Pattern = "[^0-9]"
WScript.echo oRegEx.Replace(Now(), "")



My System SpecsSystem Spec
Old 10-28-2008   #4 (permalink)
Dr J R Stockton


 
 

Re: How do I replace all characters in the "Now" date?

In microsoft.public.scripting.vbscript message <Xns9B45B6D3047C2eejj99@xxxxxx
94.109.133.242>, Tue, 28 Oct 2008 16:58:26, Evertjan. <exjxw.hannivoort@
interxnl.net> posted:
Quote:

>Ed wrote on 28 okt 2008 in microsoft.public.scripting.vbscript:
>
Quote:

>> I'm trying to rename a file using all of the characters (including the
>> time) from the "Now" command, but I'm stuck.
>>
>> This is very close (but it doesn't include the time, only the date):
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> N=Now
>> strFNA = Right(Year(N),4) & "." & Right(100+Month(N),2) & "." &
>> Right(100+Day(N),2)
>> objFSO.MoveFile "testfile.txt", strFNA & ".txt"
>>
>> All I want the filename to be is numeric digits and the extension.
>
>strDateFile = year(N) & T(month(N),2) & T(day(N),2) &_
> T(hour(N),2) & T(minute(N),2) & ".txt"
>
>function T(s,n)
> T = right("000"&s,n)
>end function
>
>not tested
"0"&s or 100+s should do; not tested for this article.

N = Now
strDateFile = (year(N)*1e10 + month(N)*1e8 + day(N)*1e6 + _
hour(N)*1e4 + minute(N)*1e2 + second(N)) & ".txt"

document.write strDateFile ' Tested

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm vb-dates.htm pas-time.htm critdate.htm etc.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Fetch special characters like "Ñ" and absolute URL from href attribute of anchors VB Script
How to prevent that the lower part of the characters <g, j, p, q, y> are "cut off" at the four top lines <From:, Date:, To:, Subject:>?? Vista mail
Blank "Date Taken / Date Modified" field in Vista Vista file management
How to insert the "modified time" attribute in "date taken" attribute in batch mode-in vista or theough a software? Vista file management
How to insert the "modified time" attribute in "date taken" attrib Vista music pictures video


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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46