I want to create a table with DATE
Column. For that column I am using DateTime
datatype .
我想用DATE列创建一个表。对于该列,我使用DateTime数据类型。
Is there any other datatype or option to display only date without Time. am using Sql Server 2005
是否有任何其他数据类型或选项仅显示没有时间的日期。我正在使用Sql Server 2005
Have any format to use?
有什么格式可以使用吗?
Otherwise if i use Datetime
datatype, how can I retrieve in c# with Update
query.
否则,如果我使用Datetime数据类型,如何使用Update查询在c#中检索。
I use C# code how to retrieve only date
我使用C#代码如何只检索日期
SqlCommand cmd = new SqlCommand(("Update tablename set Date = convert(GETDATE(),103) where Name ='" + TextBox1.Text + "' "), con);
5 个解决方案
#2
0
SELECT replace(convert(varchar, getdate(), 111), '/','-' ) -> YYYY-MM-DD
Have a look at How to format datetime & date in Sql Server 2005
看看如何在Sql Server 2005中格式化日期时间和日期
#3
0
You can use SQL Server formatting functions with convert functions. Here is the link where you can find all the formatting functions.
您可以将SQL Server格式化函数与转换函数一起使用。这是您可以找到所有格式化功能的链接。
http://www.sql-server-helper.com/tips/date-formats.aspx
If you use SQL Server 2008 then only you can use date type.
如果您使用SQL Server 2008,则只能使用日期类型。
#4
0
The DATE data type was not introduced until SQL Server 2008. As a datatype, it is not part of 2005. You have to store it as a DATETIME and then use a conversion of some sort to strip the time part off.
直到SQL Server 2008才引入DATE数据类型。作为数据类型,它不是2005的一部分。您必须将其存储为DATETIME,然后使用某种转换来剥离时间部分。
Also, SQL Server 2005 is no longer a supported platform. You should really consider upgrading to a newer platform anyway.
此外,SQL Server 2005不再是受支持的平台。无论如何,您应该考虑升级到更新的平台。
#5
0
Follow this pattern,
遵循这种模式,
const string updateTable = "UPDATE [dbo].[Tablename]
SET [Date] = getutcdate()
WHERE [Name] = @Name;"
using (var connection = new SqlConnection(youConnectionString))
{
using(var command = new SqlCommand(updateTable, connection))
{
command.Parameters.AddWithValue("@Name", TextBox1.Text);
connection.Open();
command.ExecuteNonQuery();
}
}
#1
#2
0
SELECT replace(convert(varchar, getdate(), 111), '/','-' ) -> YYYY-MM-DD
Have a look at How to format datetime & date in Sql Server 2005
看看如何在Sql Server 2005中格式化日期时间和日期
#3
0
You can use SQL Server formatting functions with convert functions. Here is the link where you can find all the formatting functions.
您可以将SQL Server格式化函数与转换函数一起使用。这是您可以找到所有格式化功能的链接。
http://www.sql-server-helper.com/tips/date-formats.aspx
If you use SQL Server 2008 then only you can use date type.
如果您使用SQL Server 2008,则只能使用日期类型。
#4
0
The DATE data type was not introduced until SQL Server 2008. As a datatype, it is not part of 2005. You have to store it as a DATETIME and then use a conversion of some sort to strip the time part off.
直到SQL Server 2008才引入DATE数据类型。作为数据类型,它不是2005的一部分。您必须将其存储为DATETIME,然后使用某种转换来剥离时间部分。
Also, SQL Server 2005 is no longer a supported platform. You should really consider upgrading to a newer platform anyway.
此外,SQL Server 2005不再是受支持的平台。无论如何,您应该考虑升级到更新的平台。
#5
0
Follow this pattern,
遵循这种模式,
const string updateTable = "UPDATE [dbo].[Tablename]
SET [Date] = getutcdate()
WHERE [Name] = @Name;"
using (var connection = new SqlConnection(youConnectionString))
{
using(var command = new SqlCommand(updateTable, connection))
{
command.Parameters.AddWithValue("@Name", TextBox1.Text);
connection.Open();
command.ExecuteNonQuery();
}
}