SSIS VB Script convert datetime to date

Posted on 2014-07-15
Last Modified: 2016-02-11
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.
Question by:Jim Horn
    LVL 21

    Accepted Solution

    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.
    LVL 65

    Author Comment

    by:Jim Horn
    That doesn't help.
    LVL 35

    Assisted Solution

    by:Miguel Oz
    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

    LVL 83

    Assisted Solution

    You can do a

    SELECT CAST(dtStartPackage as date)

    and reuse the existing variable if you don't want another variable.
    LVL 65

    Author Closing Comment

    by:Jim Horn
    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.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now