[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SSIS VB Script convert datetime to date

Posted on 2014-07-15
5
Medium Priority
?
523 Views
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.
Jim
0
Comment
Question by:Jim Horn
5 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 1000 total points
ID: 40196913
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
 
LVL 66

Author Comment

by:Jim Horn
ID: 40197126
That doesn't help.
0
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 500 total points
ID: 40198626
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
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 500 total points
ID: 40199299
You can do a

SELECT CAST(dtStartPackage as date)

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

Author Closing Comment

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

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

834 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