没有时间的日期时间!
我使用以下语句来生成随机日期:
DATEADD(day, DATEDIFF(day, 1, GETDATE()) - 1 - FLOOR(RAND(CAST(NEWID() AS binary(4))) * 365.25 * 90), 10)
但是,我得到以下格式:
1974-01-28 00:00:00.000
如何摆脱时间部分 00:00:00.000 ?
I'm using the following statement to generate random dates:
DATEADD(day, DATEDIFF(day, 1, GETDATE()) - 1 - FLOOR(RAND(CAST(NEWID() AS binary(4))) * 365.25 * 90), 10)
But, I'm getting the following format:
1974-01-28 00:00:00.000
How can I get rid of time part 00:00:00.000 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用的是 SQL Server 2008,则使用
date
数据类型而不是datetime
,否则您不能使用。datetime
数据类型始终存储一个时间部分。您可以通过转换为字符数据类型并传递样式参数来删除它以用于显示目的。例如,
返回
这些格式的相当全面的备忘单在这里
If you are on SQL Server 2008 then use the
date
datatype instead ofdatetime
otherwise you can't. Thedatetime
datatype always has a time component stored with it.You can remove it for display purposes though by casting to a character datatype and passing a style argument. e.g.
Returns
Quite a comprehensive cheat sheet to these formats is here
如果您使用的是 SQL Server 2008,则可以使用 DATE 数据类型而不是 DATETIME 数据时间。
或者,您可以使用 CONVERT 函数将日期转换为字符串类型(VARCHAR、CHAR 等)数据类型。
例如,
生成此
详细信息 CONVERT 格式
You can use the DATE data type instead of the DATETIME datatime if you are using SQL Server 2008.
Or, you can use the CONVERT function to convert the date to a string-type (VARCHAR, CHAR, etc.) data type.
For example
produces this
More on CONVERT formats
您不能将其保留为
Datetime
,除非您有 SQL Server 2008 并使用Date
数据类型You can't keeping it as
Datetime
, unless you have SQL Server 2008 and use theDate
datatype