获取日期的周数 [英] get week number of a date

查看:30
本文介绍了获取日期的周数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT strftime('%W', day) AS week, sum(amount) FROM MyTable GROUP BY week ORDER BY week DESC

此查询对于按周获取金额很有用.但是这个给出了一年中的周数,我可以知道如何获得月中的周数.我已经谷歌了很多.但所有结果都与年份中的周数有关,而不是与月份有关.

This query is useful to get the amount by week. But this one gives week number in year, May I know how to get week number in month. I have googled lot. But all results are related to week number in year not in month.

提前致谢.

推荐答案

您可以操作 strftime() 来获得答案.

You can manipulate strftime() to get your answer.

在给定日期和给定日期月份的第一个日期应用 strftime() 并减去它们以获得您的月份周数

Apply strftime() on given date and FIRST date of given dates month and subtract them to get your week number of month

例如

 SELECT  strftime('%W','2013-05-04')-strftime('%W','2013-05-01') +1;

SQL Fiddle 演示

这篇关于获取日期的周数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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