| Author |
Topic |
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2008-11-19 : 22:35:32
|
| [code]declare @BeginDate varchar(50)select @BeginDate = DATEADD(d, DATEDIFF(d, 0, GETDATE()) ,0)select @BeginDate[/code] I wnat to get[code]yyyy-mm-dd[/code]For ex.2008-11-18 Please don't change the type of @BeginDate as timedate.I just want to keep it as varchar.Thanks |
|
|
cvraghu
Posting Yak Master
187 Posts |
Posted - 2008-11-19 : 23:44:24
|
| You can use CONVERT or CAST function to convert the datetime data to varchar in the specified format. Read BOL. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-20 : 01:22:04
|
| and its not at all a good thing to store date values in varchar variables. that will make date manipulations complex. Try to preserve original data types as long as you can. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-20 : 02:09:00
|
| <<I just want to keep it as varchar.>>Why? Use proper DATETIME datatype to store datesMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-11-20 : 02:09:56
|
quote: Originally posted by visakh16 and its not at all a good thing to store date values in varchar variables. that will make date manipulations complex. Try to preserve original data types as long as you can. and let the front end do the formation
MadhivananFailing to plan is Planning to fail |
 |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2008-11-20 : 09:13:18
|
| I need it as a varchar.It will be concatenated with other strings.Need help! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-20 : 09:22:58
|
| [code]declare @BeginDate datetimeselect @BeginDate = DATEADD(d, DATEDIFF(d, 0, GETDATE()) ,0)select CONVERT(varchar(11),@BeginDate,121)[/code] |
 |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2008-11-20 : 10:00:10
|
Thanks.If @BeginDate is a string, can we use where t1 between @BeginDate and @EndDate Does the system know it is representing time and date? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-20 : 10:15:33
|
quote: Originally posted by zhshqzyc Thanks.If @BeginDate is a string, can we use where t1 between @BeginDate and @EndDate Does the system know it is representing time and date?
if t1 is datetime it will tried to convert it to datetime and if they contain valid date values it will work fine. |
 |
|
|
|