没有时间的日期时间!

发布于 2024-10-09 19:44:17 字数 239 浏览 0 评论 0原文

我使用以下语句来生成随机日期:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

失去的东西太少 2024-10-16 19:44:17

如果您使用的是 SQL Server 2008,则使用date 数据类型而不是datetime,否则您不能使用。 datetime 数据类型始终存储一个时间部分。

您可以通过转换为字符数据类型并传递样式参数来删除它以用于显示目的。例如,

select CONVERT(varchar,GETDATE(),105)

返回

30-12-2010

这些格式的相当全面的备忘单在这里

If you are on SQL Server 2008 then use the date datatype instead of datetime otherwise you can't. The datetime 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.

select CONVERT(varchar,GETDATE(),105)

Returns

30-12-2010

Quite a comprehensive cheat sheet to these formats is here

纸短情长 2024-10-16 19:44:17

如果您使用的是 SQL Server 2008,则可以使用 DATE 数据类型而不是 DATETIME 数据时间。

或者,您可以使用 CONVERT 函数将日期转换为字符串类型(VARCHAR、CHAR 等)数据类型。

例如,

CONVERT(VARCHAR, GETDATE(), 101)

生成此

12/29/2010

详细信息 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

CONVERT(VARCHAR, GETDATE(), 101)

produces this

12/29/2010

More on CONVERT formats

弃爱 2024-10-16 19:44:17

您不能将其保留为 Datetime,除非您有 SQL Server 2008 并使用 Date 数据类型

You can't keeping it as Datetime, unless you have SQL Server 2008 and use the Date datatype

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文