sql查询排序日期月份明智 [英] sql query for sorting a date month wise
问题描述
我的项目中有一个数据网格,其中有一个日期字段.
问题是我想在运行时将日期显示为dd/mm/yyyy,并希望按月升序对日期进行排序.
如果我将日期格式作为mm/dd/yyyy,则月份可以完美排序,但是如果我采用dd/mm/yyyy格式,则按日期排序,即dd而不是月份.
请帮助我进行查询.
i have a datagrid in my proj that has a date field.
the problem is that i want to show the date at run time as dd/mm/yyyy and want to sort the date by month in ascending order.
if i take date formate as mm/dd/yyyy then the month is sorted perfectly but if i take dd/mm/yyyy formate then it sorts by day ie dd instead of month .
plz help me with the Query.
推荐答案
尝试:
SELECT * FROM myTable ORDER BY Year(myDateColumn), Month(myDateColumn)
永远不要只按月份排序:您还需要年份才能有意义.
[edit]当我发布示例时,它没有任何意义...:doh:-OriginalGriff [/edit]
Never try to sort only by the month: You need the year as well to be meaningfull.
[edit]Example given made no sense when I posted it... :doh: - OriginalGriff[/edit]
SELECT tblBills.*, MonthName(month(tblBills_1.Due_Date)) AS month1
FROM tblBills inner join tblBills AS tblBills_1
on tblBills.ID=tblBills_1.ID
order by tblBills_1.Due_Date
试试这个代码,它会起作用的!!
try This code ,it will work!!
尝试这个链接
点击 [
Try this link
Click[^]
这篇关于sql查询排序日期月份明智的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!