仅在dd-mm中转换日期功能 [英] Convert Date function in dd-mm only

查看:46
本文介绍了仅在dd-mm中转换日期功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中的日期为12-4-1989 12:00:00 AM,我想在页面上仅显示该日期的DD-MM部分,因为任何转换日期功能都无法使用此格式.

还有其他方法可以实现这一目标...


I have date 12-4-1989 12:00:00 AM in my database I want to display only DD-MM part of the date on the page is ther any convert date function to reterive this format.

is any other way to achive this...

any one know kindly help me plz...

推荐答案

您可以在SQL Server或ASP.Net C#代码中完成此操作.

在C#中->
You can do this both in SQL Server or in the ASP.Net C# code.

In C# ->
String format = "dd-MM";
String dateStr = date.ToString(format);



在SQL Server中->



In SQL Server ->

SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) AS [DD MM]


尝试
select convert(varchar(5), getdate(), 105)


假设您有一个开始的日期,将getdate()替换为您的列,您将得到dd-mm.


this assumes that you have a date to start with, by replacing getdate() with your column you will get dd-mm.



请参见下面的代码:

Hi,
See the code below:

DateTime dt = Convert.ToDateTime("12-4-1989 12:00:00 AM"); //Coming from your DB, I have hardcoded here
 string dt1 = String.Format("{0:dd-MM}", dt);




现在,根据需要使用dt1....




Now, Use the dt1 as you want....


这篇关于仅在dd-mm中转换日期功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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