Computing.Net > Forums > Programming > VBS script with changing date

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBS script with changing date

Reply to Message Icon

Name: Pitt
Date: April 16, 2009 at 14:07:13 Pacific
OS: Windows XP
Subcategory: General
Comment:

I am trying to automate a daily log, but the command to save the log has the date and time in it. I need to find a way to have the script update portions of itself with the curent date.

ex.
Dslogread –s yyyymmddhhmmss –e yyyymmddhhmmss
dslogread -s 20090415060000 -e 20090416060000

The command views the log which I will be capturing for a 24 hour period from 6 am to 6 am.

I would also be using a changing date reference in the saving of the file, but once I can get the script to manipulate the command, the file saving part would be easy.



Sponsored Link
Ads by Google

Response Number 1
Name: Pitt
Date: April 16, 2009 at 14:22:16 Pacific
Reply:

I did find out a trick by creating a .txt file with .LOG in the first line that will have the current time adn date in the .txt file each time you open it. I just need to be able to reference that in the script.... Unless there's an easier way with in a VBscript.


0

Response Number 2
Name: Pitt
Date: April 16, 2009 at 20:36:19 Pacific
Reply:

Ok, I had a chance to search some more and found the Now$ and Date$ variables.

How would you go about reformating those into the format within the command. The month and day needs to be two digit also.

Dslogread –s yyyymmddhhmmss –e yyyymmddhhmmss


0

Response Number 3
Name: reno
Date: April 16, 2009 at 22:10:32 Pacific
Reply:

d=year(date)*10000+month(date)*100+day(date)
t=hour(time)*10000+minute(time)*100+second(time)
wsh.echo d & t


0

Response Number 4
Name: Pitt
Date: April 17, 2009 at 05:52:55 Pacific
Reply:

Hey that works great... almost!

I can get this output:
dslogread -s 4/16/2009060000 -e 20090417060000 -N 6

Using this code:

d=year(date)*10000+month(date)*100+day(date)
y = DateAdd("d", -1,(date))
oShell.SendKeys "dslogread -s "
oShell.SendKeys y &"060000 -e "
oShell.SendKeys d &"060000 -N 6"

Now I just need to get the "/"s out. I tried:

y = DateAdd("d", -1,year(date)*10000+month(date)*100+day(date))

But get an error.



0

Response Number 5
Name: Pitt
Date: April 17, 2009 at 07:09:05 Pacific
Reply:

Success!

d=year(date)*10000+month(date)*100+day(date)
y=year(date)*10000+month(date)*100+day(date)-1
oShell.SendKeys "dslogread -s "
oShell.SendKeys y &"060000 -e "
oShell.SendKeys d &"060000 -N 6"

Thanks for the point in the right direction!


0

Related Posts

See More



Response Number 6
Name: reno
Date: April 17, 2009 at 07:57:09 Pacific
Reply:

y=year(date)*10000+month(date)*100+day(date)-1
!!!! bug 1/1/2009 1/2/2009

y=year(date-1)*10000+month(date-1)*100+day(date-1)


0

Response Number 7
Name: Pitt
Date: April 17, 2009 at 08:15:44 Pacific
Reply:

Ahhh, glad I checked back in. Thanks for catching my bug!

One last question. When I save these files, I try to emulate the current naming format with is:
Node_YY_MM_DD(-1).txt
or
024_09_04_16.txt <--yesterday's date

Having trouble finding a way to use underscore separators and use yesterday's date. The date formats that I have seen so far don't allow for this type of format.

Any ideas?


0

Response Number 8
Name: Pitt
Date: April 17, 2009 at 08:25:18 Pacific
Reply:

This is what I have.

set oShell = CreateObject("WScript.Shell")

oShell.run"notepad.exe"

WScript.Sleep 500

y= year(date-1)*10000+month(date-1)*100+day(date-1)

oShell.SendKeys "024_"

oShell.SendKeys y &".txt"

And it outputs:
024_20090416.txt

It's close, but there are other scripts looking for the file logs to parse data out of these logs, and the file name nees to be in the correct format those other scripts are looking for.

I kinda inherited these other scripts and I don't really want to go tinkering with them.


0

Response Number 9
Name: reno
Date: April 17, 2009 at 09:13:42 Pacific
Reply:

today date:

d=array(year(date),right("0"&month(date),2),right("0"&day(date),2))
wsh.echo join(d,"_")

or

d=year(date)&"_"&right("0"&month(date),2)&"_"&right("0"&day(date),2)
wsh.echo d


0

Response Number 10
Name: Pitt
Date: April 17, 2009 at 09:47:57 Pacific
Reply:

Almost there, just need yesterday's day in this and i'm golden!

set oShell = CreateObject("WScript.Shell")
oShell.run"notepad.exe"
WScript.Sleep 500

p= right("0" & day(date()),2) 'Gives two-digit day of month.
m= right("0" & month(date()),2) 'Gives two-digit month.
y= right("" & year(date()),2) 'Gives four digit year.

oShell.SendKeys "024_" & y &"_" & m &"_" & p &".txt"


0

Response Number 11
Name: Pitt
Date: April 17, 2009 at 09:48:57 Pacific
Reply:

Sorry, didn't see your post Reno! I'll give that a try and let you know.

Thanks!


0

Response Number 12
Name: Pitt
Date: April 17, 2009 at 09:52:25 Pacific
Reply:

actually, i just figured out the right spot for the -1 to give yesterday's date and it works like this:

set oShell = CreateObject("WScript.Shell")
oShell.run"notepad.exe"
WScript.Sleep 500

p= right("0" & day(date()-1),2) 'Gives two-digit day of month.
m= right("0" & month(date()-1),2) 'Gives two-digit month.
y= right("" & year(date()-1),2) 'Gives two-digit year.

oShell.SendKeys "024_" & y &"_" & m &"_" & p &".txt"


0

Response Number 13
Name: BharathiD
Date: June 13, 2009 at 01:01:10 Pacific
Reply:

You might want to try this

Dim fileDate
Dim FileTime
Dim dtYesterday
dtYesterday = DateAdd( "d", -1, Date() )
FileDate = (Year(dtYesterday)*100+ Month(dtYesterday) )*100 + Day(dtYesterday)
Filetime = (Hour(Now)*100+Minute(Now))


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBS script with changing date

VB script to change favorites path www.computing.net/answers/programming/vb-script-to-change-favorites-path/13780.html

VB script to put time and date on www.computing.net/answers/programming/vb-script-to-put-time-and-date-on/18241.html

help with vbs script www.computing.net/answers/programming/help-with-vbs-script-/8228.html