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 |
|
inbs
Aged Yak Warrior
860 Posts |
Posted - 2010-12-01 : 04:30:39
|
| i want to get:'2010-12-01 00:00:00.000'i wrote this:SELECT Convert(varchar(26),DateDiff(Day,0,GetDate()+1),121)but i want in another way (without datediff) |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-12-01 : 04:39:01
|
| select dateadd(day,datediff(day,0,getdate()),0)MadhivananFailing to plan is Planning to fail |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-01 : 05:06:15
|
| Do you just want todays date without using datediff? Your query would guove the number of days from 19000101 to tomorrow.select convert(datetime,convert(varchar(8),getdate(),112))You don't need the convert datetime if it is being used somewhere that requires a datetime as yyyymmdd is always implicitely converted to the correct datetime.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
jcelko
Esteemed SQL Purist
547 Posts |
Posted - 2010-12-01 : 13:25:19
|
| You can use the ANSI/ISO temporal data types and have real dates (only 3 bytes!)CAST (CURRENT_TIMESTAMP AS DATE)But if you really want it as a DATETIME (which is called a TIMESTAMP in Standard SQL), you can cast it back or get a default casting when you insert it into a DATETIME column. CAST(CAST (CURRENT_TIMESTAMP AS DATE)) AS DATETIME)--CELKO--Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQLData and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL |
 |
|
|
|
|
|
|
|