在Microsoft SQL Server上,我尝试将get日期转换为以下格式:
yyyy-mm-ddThh:mm:ssZ
我已经尝试使用函数在varchar上转换这个日期,如下所示:
select CONVERT(varchar, CONVERT(NVARCHAR, getdate(), 127))今天,当我执行此请求时,结果是:
2018-06-22T15:18:13.463我怎样才能在格式的getdate()上使用yyyy-mm-ddThh:mm:ssZ呢?
谢谢
发布于 2018-06-22 13:30:03
更改格式的唯一方法是将日期转换为字符串,并使用类似于您所拥有的.
SELECT CONVERT(varchar(50), getdate(), 127)人们通常做的是以本机日期格式存储和操作日期,然后在导出或客户端检索之前将其转换为表示格式(例如通过网站、web服务、厚客户端等)。
发布于 2018-06-22 14:55:19
-- ================================================
-- Template generated from Template Explorer using:
-- Create Scalar Function (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
CREATE FUNCTION getdateJSON()
RETURNS nvarchar(50)
AS
BEGIN
DECLARE @ret as nvarchar(50);
select @ret = CONVERT(varchar, CONVERT(NVARCHAR, getdate(), 127));
Return @ret;
END
GO然后
select dbo.getdateJSON();https://stackoverflow.com/questions/50988913
复制相似问题