如何使用“日期”获取asp.net c#中的当前日期,星期,月份数据类型? [英] How can I get the current day,week,month in asp.net c# using "Date" datatype?
问题描述
美好的一天。
当我在数据表中使用Date数据类型时,如何获得当前日,周和月?
例如。
姓名_____________日期_Register
Joseph __________ 3/20 / 2014
Micheal _________ 3/15/2014
James ___________ 3/01/2014
下拉列表
每日
每周
每月
当我选择每日下拉菜单时显示Joseph的数据,当Weekly显示Micheal的数据时,它会显示James的数据。
请注意:我使用DateTime.Now.Date在Date Date_Register中插入日期;
感谢您的帮助。
具体取决于你想要做什么:你可以直接使用 DATEPART [ ^ ]功能:
SELECT DATEPART(d,myDateColumn) AS 日,DATEPART(周,myDateColumn) AS 周,DATEPART(m,myDateColumn) AS 月 FROM MyTable
或者您可以使用相关属性从C#中获取它们日期时间结构 [ ^ ],虽然没有包括周数,所以这里有一个扩展方法: DateTime扩展方法给周数 [ ^ ]
Good day.
How can I get the current day, week and month when i use "Date" datatype in my datatable?
for example.
Name____________Date_Register
Joseph__________3/20/2014
Micheal_________3/15/2014
James___________3/01/2014
Dropdownlist
Daily
Weekly
Monthly
when i choose Daily in dropdown it show the data of Joseph, when Weekly, it show the data of Micheal and for Monthly it show the data of James.
Take note: I inserted Date in Column Date_Register using DateTime.Now.Date;
Thanks for helping.
Exactly how depends on where you want to do it: you can retrieve it in day, month, or week number from SQL directly using the DATEPART[^] function:
SELECT DATEPART(d, myDateColumn) AS Day, DATEPART(wk, myDateColumn) AS Week, DATEPART(m, myDateColumn) AS Month FROM MyTable
Or you can get them in C# buy using the relevant properties from the DateTime structure[^], although that doesn't include the Week number, so there is an extension method for that here: DateTime Extension Method to Give Week Number[^]
这篇关于如何使用“日期”获取asp.net c#中的当前日期,星期,月份数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!