August 14, 2005 at 7:40 am
Hi,
I am creating a DTS package and in one of the steps the file that is created is automatically renamed using the current data and time. The problem is that the HOUR and MINUTES are coming in as single digits and dropping the leading zero, which of course I need.
Below is the code that I am using, I've tried various methods of getting the leading zero to show up back I cannot get it.
Any help would be greatly appreciated.
Thanks,
Mitch
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()
Dim FileDate
Dim DateString
Dim FSO
Dim File
FileDate = Date
DateString = DatePart("yyyy",FileDate) & Right("0" & _
DatePart("m",FileDate), 2) & Right("0" & DatePart("d",FileDate), 2) & _
Hour(Now) & Minute(Now)
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.GetFile("c:\temp\suo_test_2.txt")
File.Name = "test" & DateString & ".txt"
Main = DTSTaskExecResult_Success
End Function
August 14, 2005 at 4:38 pm
Just do the same as you have done for the month and day.
eg: Right("0" & Hour(Now), 2)
--------------------
Colt 45 - the original point and click interface
August 15, 2005 at 7:17 am
The function I use was based on a feature that Clipper/dBase had. There were two functions called PADL and PADR for "pad left and pad right". Basically you passed in the item to pad, the number of characters to pad and what to pad it with, so to pad to two characters, you would call it like this:
x = padl(Hour(Now), "0", 2)
The function is this:
function padl(sStr, cChar, lCnt)
padl = right(string(lLen, cChar) & trim(sStr), lCnt)
end function
The "padr" version is this:
function padr(sStr, cChar, lCnt)
padr = left(trim(sStr) & string(lLen, cChar), lCnt)
end function
Ad maiorem Dei gloriam
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply