数据类型=以mm / dd / yyyy格式表示的日期作为输出 [英] Datatype = date in mm/dd/yyyy format as a ouput

查看:148
本文介绍了数据类型=以mm / dd / yyyy格式表示的日期作为输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求。

字段中的当前值日期:2019-02-13 00:00:00.000; datatype = datetime或datatype = varchar。某些字段位于datetime和varchar中。

Current value in the field Date: 2019-02-13 00:00:00.000 ; datatype=datetime or datatype=varchar. Some fields are in datetime and varchar.

字段中的预期值日期:02/13/2019;数据类型=日期。我需要这种格式作为数据类型=日期作为输出。

Expected value in the field Date: 02/13/2019; datatype=date. I need this format as a datatype=date as a output.

我希望输出在转换到当前值字段日期之后应该是日期格式。我尝试了所有的方法,但它没有奏效。感谢帮助。

I want output should be in date format after conversion above current value field date. I tried all the ways but it didn't work. Appreciate help.

推荐答案

日期和日期时间值在SQLServer中不以任何特定格式存储

date and datetime values are not stored in any particular format in SQLServer

它可以确定要确定值的格式的应用程序。大多数情况下,它使用区域和语言设置来确定要使用的格式

Its upto the application to determine format in which value has to be determined. Most cases it makes use of regional and language settings to determine format to be used

如果要以任何特定格式返回值,则需要将值作为日期或日期时间返回并使用格式相应应用程序中可用的函数,用于以所需格式显示它

If you want value to be returned in any particular format you need to return values as date or datetime and use formatting functions available in the corresponding application for displaying it in required format

如果在SSMS中,则可以使用FORMAT 或者CONVERT函数用于此目的

If in SSMS then you can use FORMAT  or CONVERT function for this purpose

作为示例参见此图

declare @dt date = getdate()

select convert(varchar(20),@dt,103) as [dd/MM/yyyy],
 convert(varchar(20),@dt,121) AS [yyyy-MM-dd],
  convert(varchar(20),@dt,107) AS [MMM dd,yyyy],
  FORMAT(@dt,'MM/dd/yyyy') AS [MM/dd/yyyy]


/*
Output
-------------------------------------------------------------
dd/MM/yyyy	yyyy-MM-dd	MMM dd,yyyy	MM/dd/yyyy
-------------------------------------------------------------
13/02/2019	2019-02-13	Feb 13, 2019	02/13/2019

*/


这篇关于数据类型=以mm / dd / yyyy格式表示的日期作为输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆