Welcome to EMC Consulting Blogs Sign in | Join | Help

SSIS Junkie

Once upon a time this blog was a hive of activity. Now however its pretty lifeless as you can probably tell so if are pining for more of the same you can find me over at http://sqlblog.com/blogs/jamie_thomson. I look forward to seeing you there!

SSIS Nugget: Construct a timestamp value

Visitors to the SSIS forum often ask how to construct a date string in the form YYYYMMDDHHMISS (e.g. "20070207123456" for "7th February 2007, 12:34:56") using a SSIS expression. I always give the same answer so I thought I'd post the answer up here so I don't have to keep typing it. Here's the expression that I always use:

(DT_STR, 4, 1252)DATEPART("yyyy", @[System::ContainerStartTime]) +
RIGHT("0" + (DT_STR, 2, 1252)DATEPART("mm", @[System::ContainerStartTime]), 2) +
RIGHT("0" + (DT_STR, 2, 1252)DATEPART("dd", @[System::ContainerStartTime]), 2) +
RIGHT("0" + (DT_STR, 2, 1252)DATEPART("hh", @[System::ContainerStartTime]), 2) +
RIGHT("0" + (DT_STR, 2, 1252)DATEPART("mi", @[System::ContainerStartTime]), 2) +
RIGHT("0" + (DT_STR, 2, 1252)DATEPART("ss", @[System::ContainerStartTime]), 2)
 

You can of course substitute @[System::ContainerStartTime] for @[System::StartTime], GETDATE() or any column that is of type DT_DBTIMESTAMP, DT_DATE or DT_DBDATE.

-Jamie

 

 

Published 07 February 2007 22:41 by jamie.thomson

Comments

 

Darren said:

A similar collection of expressions at http://wiki.sqlis.com/default.aspx/SQLISWiki/ExpressionDateFunctions.html , started because I kept on wanting the same formats over and over. Feel free to add more.

February 14, 2007 13:47
 

john said:

Thanks again for the tips!!

The first part of the filename is dynamic in the sense I am using a For Loop to build the filename. Each iteration through the loop I'm adding a day to the filename.ie- Dal027042307.txt I'm using a filetask and am moving this file from a "Processing" folder to an "Error" folder. I then use another FileTask to rename the file from Dal027042307.txt to Dal027042307_Error_042307_16.36.39.txt

I needed a timestamp in the filename obviously so I would be able to decipher when the file errored in case I process the same file multiple times.

"Dal027"

+RIGHT("0" + (DT_STR, 2, 1252)  MONTH( GETDATE()  ), 2)

+RIGHT("0" + (DT_STR, 2, 1252)  DAY( dateadd("dd", @[User::iCounter],GETDATE())  ), 2)

+RIGHT("0" + (DT_STR, 4, 1252)  YEAR( GETDATE()  ),2)

+"_Error_"

+RIGHT("0" + (DT_STR, 2, 1252)  MONTH( GETDATE()  ), 2)

+RIGHT("0" + (DT_STR, 2, 1252)  DAY( GETDATE()  ), 2)

+RIGHT("0" + (DT_STR, 4, 1252)  YEAR( GETDATE()  ),2)

+"_"

+ RIGHT("0" + (DT_WSTR,2)DATEPART("hh", GETDATE()), 2) + "."

+ RIGHT("0" + (DT_WSTR,2)DATEPART("mi", GETDATE()), 2) + "."

+ RIGHT("0" + (DT_WSTR,2)DATEPART("ss", GETDATE()), 2)

+".txt"

April 23, 2007 21:49
 

Blair S said:

Or perhaps: -

substring(replace(replace(replace((DT_STR, 100 , 1252)(DT_FILETIME) @[User::QuickPL_Creation_Time],"-",""),":","")," ",""),2,16)

April 24, 2008 14:04
New Comments to this post are disabled

This Blog

Syndication

Powered by Community Server (Personal Edition), by Telligent Systems