how to capture timestamp with milliseconds in ssis

2019-07-13 21:52发布

问题:

How to capture current timestamp in ssis package 2016

I declared a variable and using expression but milliseconds are missing

@currenttimestamp = (DT_WSTR,50)(DT_DBTIMESTAMP)@[System::StartTime]

I want the milliseconds too

Thanks

回答1:

The issue was solved when casting to (DT_DBTIMESTAMP2,3):

(DT_WSTR,50)(DT_DBTIMESTAMP2,3)GETDATE()

but the time get changes as it using the getdate() asit returns the current time, I need the package start time I used the following

(DT_WSTR,50)(DT_DBTIMESTAMP2,3)@[System::StartTime] 

but the milliseconds is coming as .000

Do i have to use the getdate() in ExecuteSQLTask and assign that value to a string variable. I am new to ssis please give suggestions.



回答2:

Use the below comand in the Execute SQL Task at the begining of the package that will give you the exact start time of the package.

SELECT CAST(GETDATE() as datetime2(6)) 'Date';