Showing posts with label datecreated. Show all posts
Showing posts with label datecreated. Show all posts

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

Sunday, February 19, 2012

Date created defualt value

in my database i have a "datecreated" feild, its datatype is "datetime", is it possible to set the defualt value as the time now? if so what do I put in the defualt value property? thanks a million si!

Under design view for the Table, you can set he default value of "Getdate()" (without the quotes). You dont need to do anything from yout T-SQL or application. The value is automatically inserted by SQL Server.

|||

thanks a million! thats going to save sometimeBig Smile si!

Tuesday, February 14, 2012

Date and Time Parameter:

I have a report that I will use a DateCreated value for the date and time
parameters. The time stamp for the DateCreated value does carry dates and
times. This report is for three 12 hour shifts and the hours run from 7:00
PM to 7:00 AM. I need to set my default parameters to display as yesterday's
date with the time of 7:00 PM and today's with the time of 7:00 AM. How do I
write this in my sql and set my defaul parameters? Please help! Thanks,
Deborah
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200604/1Well you could base your paramter on a stored procedure which returns
yesterdays date.
"Deborah via SQLMonster.com" wrote:
> I have a report that I will use a DateCreated value for the date and time
> parameters. The time stamp for the DateCreated value does carry dates and
> times. This report is for three 12 hour shifts and the hours run from 7:00
> PM to 7:00 AM. I need to set my default parameters to display as yesterday's
> date with the time of 7:00 PM and today's with the time of 7:00 AM. How do I
> write this in my sql and set my defaul parameters? Please help! Thanks,
> Deborah
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200604/1
>