Solved

Using VBScript to capture YYMMDD format

Posted on 2008-06-11
10
999 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
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 5

Accepted Solution

by:
rstomar earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 2

Author Comment

by:kunghui80
Comment Utility
hi RobSampson,

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

rgds,
kelvin
0
 
LVL 2

Author Comment

by:kunghui80
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 22

Expert Comment

by:danaseaman
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you for your all assistance, it helps lots.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now