Link to home
Start Free TrialLog in
Avatar of kunghui80
kunghui80Flag for Singapore

asked on

Using VBScript to capture YYMMDD format

Dear Experts,

I've a file format named YYMMDD.MSG in a server, whereby
YYMMDD = today date (auto generated log file).
Eg. 080612 (12th June 2008)

I need to use VBscript to grab this file and copy to another server.

How do i capture the file name in the format YYMMDD.MSG using VBScript?

I tried to format the date, but not successful.

Hope you can assist, thanks!;)

rgds,
kelvin
ASKER CERTIFIED SOLUTION
Avatar of rstomar
rstomar

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
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia 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 kunghui80

ASKER

hi rstomar,

thanks for the format. I notice there's leading "0" problem.
The result will show 8612, instead of 080612, any ideal how could avoid this?

I've manual done like this, but wish to see if any better solutions
MyFileNameA="C:\" & "0" & CStr(Year(Now()) mod 100) & "0" & CStr(Month(Now())) & CStr(Day(Now())) & ".MSG"
hi RobSampson,

Im testing on this now, will get back to you soon.

rgds,
kelvin
I got a problem. For scenario:
Today is 1st May 2008 file generated will be (080501.MSG)

My script will always try to get yesterday file, using the script, im getting (080500.MSG)
strFileName = Right(Year(Date), 2) & Right("0" & Month(Date), 2) & Right("0" & Day(Date)-1, 2) & ".MSG"

Try this:
Option Explicit
 
Private Sub Form_Load()
   Debug.Print fYYMMDD(Now)
End Sub
 
Function fYYMMDD(ByVal dat As Date) As String
   fYYMMDD = Mid(CStr(Year(dat)), 3) & Right("0" & CStr(Month(dat)), 2) & Right("0" & CStr(Day(dat)), 2) & ".MSG"
End Function

Open in new window

If today is 1st May 2008, i'll need to get 080430.MSG file, anyway to capture the day-1?
SOLUTION
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
SOLUTION
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
Thank you for your all assistance, it helps lots.