日期时间格式更改 [英] datetime format change

查看:100
本文介绍了日期时间格式更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉提问sql问题





i有日期时间格式

喜欢dd / mm / yyyy hh:mm:ss









i需要它在dd / mm / yyy hh:mm:ss





它在sp

解决方案

这不一定像您想象的那么简单:DateTime没有格式 - 它只是自任意时间点以来的毫秒数。只有在以某种方式将其转换为字符串时才会获得格式!这可以通过CONVERT函数在SQL中: http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/ [ ^ ]或者浏览器,如果您将DateTime直接传递给显示项目,或者在您的应用程序代码中传递,如果您使用ToString(显式或隐式)。



为了使事情进一步复杂化,那里最多可以涉及三种不同的语言环境:运行任何SQL代码(包括存储过程)的SQL Server PC,运行任何C#或VB代码的Web服务器以及运行浏览器的客户端PC。根据您进行转换的位置以及操作方式,最终会采用何种格式!



在不知道您的工作方式的情况下,我们不能说这样做你会得到你想要的格式(但用户可能不想要)

在我们给你一个明确的答案之前,你需要仔细看看你在做什么。


SELECT CONVERT(VARCHAR(6),GETDATE(),101)+ RIGHT(CONVERT(VARCHAR(10),GETDATE(),101),3)+''+ CONVERT(VARCHAR(8) ,GETDATE(),108)as FormatedDate


这可以完成 >:

选择 CONVERT VARCHAR 10 ),GETDATE(), 103 )+ ' ' + convert VARCHAR 8 ),GETDATE(), 14

希望它有所帮助


guys sorry to ask sql question


i have datetime format
like dd/mm/yyyy hh:mm:ss




i need it in dd/mm/yyy hh:mm:ss


its there in sp

解决方案

This is not necessarily as simple as you think: a DateTime doesn't have a format - it is just a number of milliseconds since an arbitrary point in time. It only gets a format when you convert it to a string in some way! This could be in SQL via the CONVERT function: http://anubhavg.wordpress.com/2009/06/11/how-to-format-datetime-date-in-sql-server-2005/[^] or in the browser if you pass a DateTime direct to display items, or in your application code if you use ToString (either explicitly or implicitly).

To complicate things further, there are up to three different locales that could be involved here: The SQL server PC where any SQL code including stored procedures are run, the web server where any C# or VB code is run, and the client PC were the browser runs. Depending on where you do the conversion and how you do it, what format you will end up with!

Without knowing how you are working, we can't say "do this" and you will get the format you want (but the user might not want)
You need to look at exactly what you are doing before we could give you a definitive answer.


SELECT CONVERT(VARCHAR(6), GETDATE(), 101) + RIGHT(CONVERT(VARCHAR(10), GETDATE(), 101),3) + ' ' + CONVERT(VARCHAR(8), GETDATE(), 108) as FormatedDate


This can be done as follows :

select CONVERT(VARCHAR(10), GETDATE(), 103) + ' '  + convert(VARCHAR(8), GETDATE(), 14)

Hope it helps


这篇关于日期时间格式更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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