Solved

Using VBScript to capture YYMMDD format

Posted on 2008-06-11
10
1,058 Views
Last Modified: 2010-07-27
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
0
Comment
Question by:kunghui80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 5

Accepted Solution

by:
rstomar earned 100 total points
ID: 21765917
CStr(Year(Now())) & CStr(Month(Now())) & CStr(Day(Now()))   will give you a string in yyyymmdd format.
Use CStr(Year(Now()) mod 100)  for yy
0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 150 total points
ID: 21765920
Hi,

This string will give you the file name.

strFileName = Right(Year(Date), 2) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & ".MSG"

Regards,

Rob.
0
 
LVL 2

Author Comment

by:kunghui80
ID: 21766012
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"
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 2

Author Comment

by:kunghui80
ID: 21766020
hi RobSampson,

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

rgds,
kelvin
0
 
LVL 2

Author Comment

by:kunghui80
ID: 21766175
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"

0
 
LVL 22

Expert Comment

by:danaseaman
ID: 21766178
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

0
 
LVL 2

Author Comment

by:kunghui80
ID: 21766184
If today is 1st May 2008, i'll need to get 080430.MSG file, anyway to capture the day-1?
0
 
LVL 22

Assisted Solution

by:danaseaman
danaseaman earned 50 total points
ID: 21766197
For yesterdays date try this:
Option Explicit
 
Private Sub Form_Load()
   Debug.Print fYYMMDD(Now)
End Sub
 
Function fYYMMDD(ByVal dat As Date) As String
   dat = dat - 1
   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

0
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 150 total points
ID: 21766539
This will do it.

Regards,

Rob.
dteYesterday = DateAdd("d", -1, Date)
strFileName = Right(Year(dteYesterday), 2) & Right("0" & Month(dteYesterday), 2) & Right("0" & Day(dteYesterday), 2) & ".MSG"

Open in new window

0
 
LVL 2

Author Comment

by:kunghui80
ID: 21767588
Thank you for your all assistance, it helps lots.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question