I am working on a query in Sql Server 2005 where I need to convert a value in DateTime
variable into a varchar
variable in yyyy-mm-dd
format (without time part). How do I do that?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
I have fixed data length of
char(10)
as you want a specific string format.Try the following:
For a full date time and not just date do:
See this page for convert styles:
http://msdn.microsoft.com/en-us/library/ms187928.aspx
OR
SQL Server CONVERT() Function
With Microsoft Sql Server:
The OP mentioned datetime format. For me, the time part gets in the way.
I think it's a bit cleaner to remove the time portion (by casting datetime to date) before formatting.
The shortest and the simplest way is :
-- This gives you the time as 0 in format 'yyyy-mm-dd 00:00:00.000'