如何将1 6 2012转换为1june2012 [英] how 1 6 2012 can be converted into 1june2012

查看:100
本文介绍了如何将1 6 2012转换为1june2012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将1 6 2012转换为1june2012,请尽快帮助我 ..
thnx

OP最初使用C#标记发布了问题,某些答案基于该考虑.

how 1 6 2012 can be converted into 1june2012 please help me as soon as possible..
thnx

EDIT : OP intially posted the question with C# tag, some answer are based on that consideration.

推荐答案

看一下下面的SQL解决方案:

Look at this solution in SQL:

DECLARE @date NVARCHAR(10) = '1 6 2012'

SET @date = REPLACE(@date, ' ', '.')

SELECT CONVERT(VARCHAR, CONVERT(DATETIME, @date, 104), 6)




这是差异. SQL Server支持的格式.

http://msdn.microsoft.com/en-us/library/aa226054 (v = sql.80).aspx [
希望对您有所帮助.




Here are the diff. formats supported by SQL Server.

http://msdn.microsoft.com/en-us/library/aa226054(v=sql.80).aspx[^]

The input you provided is not a valid format and I had to tweak it to get the correct format i.e. 106.

I replaced the blank spaced with a ''DOT''.

Hope this helps.


您好,Deepshikha,

在SQL Server中,请执行以下操作(我假设您提到的数据为-"1 6 2012")

Hi Deepshikha,

In SQL Server, do like this ( I assume the data as you''ve mentioned to be -"1 6 2012")

select  CONVERT(datetime,(RIGHT(dateCol,4)+'-'+ SUBSTRING(dateCol,3,1) +'-'+LEFT(dateCol,1))) from testTable;



如果您希望它成为-"2012年6月1日",请尝试以下操作:



if you want it to be -"01 Jun 2012" then try this:

SELECT CONVERT(VARCHAR(11), CONVERT(datetime,(RIGHT(testCol,4)+'-'+ SUBSTRING(testCol,3,1) +'-'+LEFT(testCol,1))), 106) AS [DD MON YYYY] from testTable;



希望这能达到目的.

干杯!
快乐编码:)

Sunny_K



Hope this serves the purpose.

Cheers!
Happy Coding :)

Sunny_K


为此使用convert.todatetime方法
例如:-
use convert.todatetime method for this
example:-
string dt1 = Convert.ToDateTime(UrDate).ToString("ddMMMMyyyy");


这篇关于如何将1 6 2012转换为1june2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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