Link to home
Start Free TrialLog in
Avatar of Erdrick33
Erdrick33

asked on

date variable in VBscript

Regarding a question I posted here: https://www.experts-exchange.com/questions/22602293/User-query-in-LDAP.html
Chris gave me an excellent script to run, however I'm looking at automating it, however using a constant for the file name will not work.  I'm looking to use a date function to output the filename with the date as follows: mm-dd-yyyy

Thanks so much in advance
Avatar of amit_g
amit_g
Flag of United States of America image

Change

Const REPORT_FILE = "Users.csv"

to

Dim REPORT_FILE
Dim Today

REPORT_FILE =

Today = Date()
REPORT_FILE = Month(Today) & "-" & Day(Today) & "-" & Year(Today)
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Erdrick33
Erdrick33

ASKER

Appreciate it once again Chris,
I'm not that familiar with VB yet, and I was trying to do this calling WSH, using the shell command, something like retval = ("%date:/=-%.csv) and I couldn't get it to work.  Thanks again, you're a life saver.

Cheers,
Erdrick33

You're welcome :)

Chris
Chris, sorry, forgot to ask you one other thing in that one... how would I go about changing the path to a server share in this program?
NM Chris, I figured it out... seems like the programming knowledge might be seeping back in.

Cheers

Just a case of prefixing it onto the File name variable. Something like this:

Const FILE_SERVER = "\\SomeServer\SomeShare\"

strFileName = FILE_SERVER & strMonth & "-" & strDay & "-" & strYear & ".csv"

Should work well enough.

Chris

:)

Just a slight note on the above. If it's running as an automated task I normally prefer to create the file locally, then move it onto the server as a separate step. Then if the server is unavailable you at least have the local copy to work with.

Chris
Thanks for the tip, but I'm running it from the server, so if it's down, I suppose it wont run anyhow :o)