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("RSTabl es").Value
oRS.MoveFirst()
Const ForReading = 1
Const ForWriting = 2
dim fso
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Dim ResultFile, objResult
dim strSourceFile
dim strFilePath
strFilePath = DTSGlobalVariables("FilePa th").Value
ResultFile = strFilePath & Month(Date) & day(date-1) & right(year(date),2) & DTSGlobalVariables("Source FileName") .Value
Set objResult = fso.OpenTextFile(ResultFil e, 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
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("RSTabl
oRS.MoveFirst()
Const ForReading = 1
Const ForWriting = 2
dim fso
Set fso = CreateObject("Scripting.Fi
Dim ResultFile, objResult
dim strSourceFile
dim strFilePath
strFilePath = DTSGlobalVariables("FilePa
ResultFile = strFilePath & Month(Date) & day(date-1) & right(year(date),2) & DTSGlobalVariables("Source
Set objResult = fso.OpenTextFile(ResultFil
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
right(cstr(100+day(date-1)
right(year(date),2) & DTSGlobalVariables("Source
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.