AAAaaaaah...Yesterday was just one of those days. I was trying to do something very simple in a script task - assign the current datetime value to one of my variables - and was pulling my stubbly hair out trying to do it.
I am happy to confess to not being the strongest .netter in the world but we do also in SSIS get a pretty pony script editor in which to do our work. Anyways, I digress. Why was I finding this so hard?
Well I had written this.
Dts.Variables("myvariable") = Now.Date()
Which is fine if you just want the date. I didn't I wanted the time component as well. So I dutifully edited my code deleting the Date() bit to get me back to here bring up the intellisense.
Dts.Variables("myvariable") = Now.
I scanned the drop down looking for the date time option I needed and I couldn't find it anywhere! How rubbish is that! I could see every other imaginable component of the date but not the full datetime. My brain then did an odd thing.
I thought perhaps I need to build up a string using all these properties to get to my date time. That would be RUBBISH I thought but would probably get me to where I needed to be. However, fortunately for me, Simon Sabin was online and so I asked him about my problem.
"How about just using Now()" he said. "Does that work" I replied. "I thought I needed to use a property!". Simon proceeded to wet himself laughing at my little misfortune.
Sure enough I tried it and
Dts.Variables("myvariable") = Now()
sets the variable to the current date time. Magic. I had completely forgotten that the rest of this stuff is an inheritance of the base object. At least I assume that is what is going on. At the end of the day I am very glad I have a C# fundamentals course booked in as part of my training plan. Roll on SQL 2008, C# in SSIS and a dream of better editors to make up for my stunning ignorance.
Cheers, James