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.
| Author |
Topic |
|
GTIMANiac
Starting Member
4 Posts |
Posted - 2004-05-17 : 16:52:38
|
| I have an app that allows users to set preferences. By default the tables are populated with FiscalYear StartDates and StopDates, as are all the queries within the app if the user has not setup preferences.I basically need to set the StartDate to 10/1/LastYear and the StopDate as 9/30/CurrentYearI tried the following with no success.(('10/1/') + DateAdd(yyyy, -1, (getDate())))and(('9/30/') + DatePart(yyyy, (getDate())))Should I be using CAST or CONVERT?Tia-Scott |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-05-17 : 16:59:12
|
| Use DATEPART instead of DATEADD:SELECT '10/1/' + CONVERT(VARCHAR(4), DATEPART(yyyy, GETDATE()) - 1)SELECT '9/30/' + CONVERT(VARCHAR(4), DATEPART(yyyy, GETDATE()))Have to use CONVERT since DATEPART returns an INT and you can't concatenate a string with an INT without the CONVERT.Tara |
 |
|
|
GTIMANiac
Starting Member
4 Posts |
Posted - 2004-05-17 : 17:05:25
|
| Thank you, and thank you for the explaination as well. Works like a champ!-Scott |
 |
|
|
|
|
|