SSIS VB Script convert datetime to date

Hi All

In SSIS 2012 I have a SQL task to store GETDATE() into variable dtStartPackage.  Works fine.
SELECT GETDATE() as dtStartPackage

Open in new window

In a Script Task I'd like to take that variable and assign just the date part ( i.e. without the time ) to a script variable.
Here's what I have so far, which stores both date and time into the variable dtStartPackage:
Dim dtStartPackage As Date = CDate(Dts.Variables("dtStartPackage").Value)

Open in new window

Question: How can I modify the above expression to only store the date?
I could do a SELECT CAST(GETDATE() as date) and store that in a variable, and use that variable in the script task, but I'd prefer not to create an extra variable to pull this off.

Thanks in advance.
Jim
LVL 66
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy PooleCommented:
Since SQL uses a DateTime field it will always store it as such, you could however change it to a varchar and store it that way.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:
That doesn't help.
0
Miguel OzSoftware EngineerCommented:
Any particular reason to use SELECT, you could  declare your variable as DATE type:
DECLARE @dtStartPackage as DATE
SET @dtStartPackage = GETDATE()

Open in new window

0
CodeCruiserCommented:
You can do a

SELECT CAST(dtStartPackage as date)

and reuse the existing variable if you don't want another variable.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:
I've moved to a different gig and can't continue this issue, so I'm going to close the question and spread the wealth around.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.