SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Expression --need 2 digit not 4


Expression --need 2 digit not 4

Author
Message
JAMIEM-548127
JAMIEM-548127
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 605
I am trying to create an expression in ssis as follows:
"capp"+(DT_STR,4,1252) DatePart("yy",getdate()) +
Right("0" + (DT_STR,2,1252) DatePart("m",getdate()),2) +
Right("0" + (DT_STR,2,1252) DatePart("d",getdate()),2) + ".txt"

Displays
capp20080124.txt

What I want is capp080124.txt and I not sure how to get the year to be two digits and not four? Please help..
alane 46264
alane 46264
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 23
Replace

(DT_STR,4,1252) DatePart("yy",getdate())

with

Right((DT_STR, 4, 1252)DatePart("yyyy", getdate()), 2)

This will return the last two (Right) digits of the year (ignoring the "20" century).
Phil Parkin
Phil Parkin
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19266 Visits: 20462
alane 46264 (11/15/2013)
Replace

(DT_STR,4,1252) DatePart("yy",getdate())

with

Right((DT_STR, 4, 1252)DatePart("yyyy", getdate()), 2)

This will return the last two (Right) digits of the year (ignoring the "20" century).


You just answered a five-year-old post - hope that they were not sitting there waiting! :-D


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search