Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 simple create date

Author  Topic 

obewankanoochie
Starting Member

24 Posts

Posted - 2008-10-06 : 18:34:32
I'm trying to create a date using the following SQL:

CAST(year(dateAdd("year",1,getdate())) + '/' & month(getdate()) + '/' + day(getdate()) AS smalldatetime) AS moderndate

Can someone tell me what I'm doing wrong?

Thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-06 : 18:36:50
Well could you explain in words what you are trying to do?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

obewankanoochie
Starting Member

24 Posts

Posted - 2008-10-06 : 18:44:55
sorry. I'm trying to create a smalldatetime variable that looks like '2009-10-06'. I might be passing in other values for month and date though, so I was trying to put three variable together (year/month/day). thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-06 : 18:49:14
smalldatetime holds the time value too, so just use this: DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0)

Or for variables:
@year + '/' + @month + '/' + @day

But you'll get 00:00 for time.


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -