Saturday, February 25, 2012

Date Format

Hi,

I'm conditional split and I want to get the data base on getdate with a format: Here's the scenario:

I hava a column datecreated with a default value of getdate() format

I want to convert the datecreated format like (ex 01/01/2007) ==

getdate with a format also like '01/01/2007"

Can anyone help with this, at least a sample

also I tried to use this

(DT_WSTR,2)DATEPART("MM",DateCreated) + "/" + (DT_WSTR,2)DATEPART("DD",DateCreated) + "/" + (DT_WSTR,4)DATEPART("YYYY",DateCreated) == (DT_WSTR,2)DATEPART("MM",GETDATE()) + "/" + (DT_WSTR,2)DATEPART("DD",GETDATE()) + "/" + (DT_WSTR,4)DATEPART("YYYY",GETDATE())

But I still don't get the right record

Thanks

The expression you are using to create the date string from GETDATE() will result in strings such as 1/1/2007, but it looks like you want to compare that to 01/01/2007. You can use the following modification to the right hand side of your comparison to pad the month and day with leading zeros:

RIGHT("0" + (DT_WSTR,2)DATEPART("MM",GETDATE()), 2) + "/" + RIGHT("0" + (DT_WSTR,2)DATEPART("DD",GETDATE()),2) + "/" + (DT_WSTR,4)DATEPART("YYYY",GETDATE())

Depending on how the datecreated column is formatted, you may or may not want to do something similar on the left side of your equation.

Let me know if this solves the problem for you.

Thanks
Mark

|||I don't understand. If both formats are timestamp formats, they you shouldn't have an issue comparing dates. Dates aren't also strings, so treating them as such doesn't make a whole heck of a lot of sense.

The issue with getdate() is that it carries with it the time component as well. Perhaps you need to cast your date fields to (DT_DBDATE) first, before comparisons.|||(DT_DBDATE)[DateCreated] == (DT_DBDATE)getdate()|||

Phil Brammer wrote:

(DT_DBDATE)[DateCreated] == (DT_DBDATE)getdate()

Hi Phil,

Thanks for the reply I'm going to check this one...

No comments:

Post a Comment