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 |
|
Msandlana
Starting Member
33 Posts |
Posted - 2008-01-22 : 06:47:40
|
| Hi all I would like anyone to help I want 2 convert a datetime to 2008-02-02 21:00 the output must leave the time just 2008-02-02If (@DateCreated <> 0)Begin Set @varSelectSql = @varSelectSql + ' And convert(varchar(10),DateCreated,121) = '+ cast(@DateCreated as varchar(10))End |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-01-22 : 06:52:32
|
| You should be doing formatting in front end of your application. Its best SQL practise not to do any kind of formatting in T-SQL. T-SQL should be used for returning queried data. |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2008-01-22 : 06:53:27
|
| I'm not sure how you want to use it in this context, but this is how it's done with the current datetime:select cast(convert(varchar(10), getdate(), 121) as datetime)Duane. |
 |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-01-22 : 06:56:39
|
| select cast(convert(varchar(10), getdate(), 121) as datetime) will still give time though it will be 00:00:00.000 like 2008-01-22 00:00:00.000. Its better you format your date with any format function available to you in front end. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-22 : 07:14:58
|
[code]IF @DateCreated IS NOT NULL AND @DateCreated > '19000101' SELECT @SQL = @SQL + ' AND DateCreated >= ' + CONVERT(CHAR(10), @DateCreated, 112), @SQL = @SQL + ' AND DateCreated < ' + CONVERT(CHAR(10), DATEADD(DAY, 1, @DateCreated), 112)[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|
|
|