We help IT Professionals succeed at work.

timestamp question

Last Modified: 2013-11-30

I have a Activex Script in DTS package. It should save in file in mmddyy format.
when it is 10-09-2007 it should save as 100907 but instead it is saving as 10907. what should i change in my code. Below is the code.

Thanks in advance,

Option Explicit

Function Main()

      Dim oRS
      Set oRS = DTSGlobalVariables("RSTables").Value

    Const ForReading = 1
    Const ForWriting = 2
dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")

    Dim ResultFile, objResult
             dim strSourceFile
             dim strFilePath
             strFilePath = DTSGlobalVariables("FilePath").Value            
      ResultFile = strFilePath   & Month(Date) & day(date-1) & right(year(date),2) & DTSGlobalVariables("SourceFileName").Value    
Set objResult = fso.OpenTextFile(ResultFile, ForWriting, True)
      do while not oRS.EOF             
             objResult.WriteLine       oRS.Fields(0).Value            


        Set objResult = Nothing

    Set fso = Nothing

      Set oRS = Nothing

      Main = DTSTaskExecResult_Success
End Function
Watch Question


A method of printing numbers with leading zeros is to add a factor of 10 more than the number of zeros.  For instance, if you wanted up to 3 zeros it would be something like

right (cstr (1000 + n), 3)

In your case, you wanted 2 leading zeros, so add 100 and take the rightmost 2 digits.

Try this

ResultFile = strFilePath   & _
    right(cstr(100+Month(Date)), 2) & _
    right(cstr(100+day(date-1)), 2) & _
    right(year(date),2) & DTSGlobalVariables("SourceFileName").Value

Also test on single digit months and days.  You will probably find that the original source on 6 May would read 5607 instead of 050607.
Most Valuable Expert 2012
Top Expert 2014
Unlock this solution and get a sample of our free trial.
(No credit card required)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.