嗨..我想以格式“Dd / Mm / Yy”从数据库中呼叫日期来自Sql [英] Hi.. I Want To Call Date From Database In Format "Dd/Mm/Yy" From Sql
本文介绍了嗨..我想以格式“Dd / Mm / Yy”从数据库中呼叫日期来自Sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
sql display是4/7/2010 12:00:00 AM
我想在标签中以dd / mm / yy
格式调用它解决方案
进行格式化的最佳位置是在客户端,所以我不会格式化数据库查询中的数据。相反,在获取数据后,包含日期的项目可以转换为具有请求格式的字符串。
请考虑以下代码
string formattedDate = System.DateTime.Now.ToString( @ < span class =code-string> dd \ / MM \ / yy);
代替DateTime.Now
将是您的日期列值
SQL Server通过使用以下方式启用自定义日期和时间格式: CAST和CONVERT(Transact-SQL) [ ^ ]功能。
你可以尝试这个 -
声明@date datetime = getdate();
选择LEFT(转换(varchar(10),@ date,103),6)+右(年(@日期),2)
请记住这将以字符串格式返回。
sql display is 4/7/2010 12:00:00 AM
and i want to call it in label in format "dd/mm/yy"解决方案The best place to do the formatting is on the client side so I wouldn't format the data in the database query. Instead, after fetching the data the item containing the date could be converted to a string with the requested format.
Consider the following code
string formattedDate = System.DateTime.Now.ToString(@"dd\/MM\/yy");
In place of theDateTime.Now
would be your date column value
SQL Server enables custom date and time formatting via using: CAST and CONVERT (Transact-SQL)[^] function.
You can try this -
declare @date datetime=getdate();
select LEFT(convert(varchar(10), @date, 103),6) + Right(Year(@date),2)
keep in mind that this will return in string format.
这篇关于嗨..我想以格式“Dd / Mm / Yy”从数据库中呼叫日期来自Sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文