Link to home
Start Free TrialLog in
Avatar of NK9
NK9

asked on

timestamp question

Hi,

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,
nk

Option Explicit

Function Main()

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

    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            
            oRS.MoveNext
      loop

        objResult.Close

        Set objResult = Nothing

    Set fso = Nothing

      Set oRS = Nothing

      Main = DTSTaskExecResult_Success
End Function
Avatar of cup
cup

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.
ASKER CERTIFIED 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