VBS script with changing date

April 16, 2009 at 14:07:13
Specs: Windows XP
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.


See More: VBS script with changing date

Report •


#1
April 16, 2009 at 14:22:16
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.

Report •

#2
April 16, 2009 at 20:36:19
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


Report •

#3
April 16, 2009 at 22:10:32
d=year(date)*10000+month(date)*100+day(date)
t=hour(time)*10000+minute(time)*100+second(time)
wsh.echo d & t

Report •

Related Solutions

#4
April 17, 2009 at 05:52:55
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.



Report •

#5
April 17, 2009 at 07:09:05
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!


Report •

#6
April 17, 2009 at 07:57:09
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)


Report •

#7
April 17, 2009 at 08:15:44
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?


Report •

#8
April 17, 2009 at 08:25:18
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.


Report •

#9
April 17, 2009 at 09:13:42
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


Report •

#10
April 17, 2009 at 09:47:57
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"


Report •

#11
April 17, 2009 at 09:48:57
Sorry, didn't see your post Reno! I'll give that a try and let you know.

Thanks!


Report •

#12
April 17, 2009 at 09:52:25
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"


Report •

#13
June 13, 2009 at 01:01:10
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))


Report •


Ask Question