sql查询排序日期月份明智

编程入门 行业动态 更新时间:2024-10-27 08:24:54
本文介绍了sql查询排序日期月份明智的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的项目中有一个数据网格,其中有一个日期字段. 问题是我想在运行时将日期显示为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查询排序日期月份明智

本文发布于:2023-06-04 22:10:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/506085.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:明智   日期   sql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!