如何在mysql中的日期格式的月份中减去一个? [英] How to subtract one to the month of a date format in mysql?

查看:1430
本文介绍了如何在mysql中的日期格式的月份中减去一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一条select语句:

Assuming I have a select statement:

SELECT COUNT(*), wedding, DATE_FORMAT(weddate, '%y %m %d') FROM weddingtable

我要使它可以从它返回的月份中减去1: 例如:

I want to make it such that I could subtract 1 from the month it would return: for example:

SELECT COUNT(*), wedding, DATE_FORMAT(weddate, '%y %m-1 %d') FROM weddingtable

它似乎只是在月份整数后面加上"-1",而不是实际从月份中减去一个.我该如何完成? (换句话说,它通常会返回5代替%m,它将返回4,依此类推).

It appears to just append "-1" to the month integer instead of actually subtracting one from the month. How do I accomplish this? (in other words, where it would normally return 5 in place of %m, it would return 4, etc.)

注意:对于一月份,我希望它可以代替%m,而应为"0".

Note: For January, I would expect in place of %m, it would be "0".

推荐答案

您的解决方案可以源自:

Your solution can be derived from: Subtract month and day mysql

例如(DATE_SUB(curdate(), INTERVAL 1 MONTH)

SELECT COUNT(*), wedding, DATE_SUB(weddate,INTERVAL 1 MONTH) FROM weddingtable

这篇关于如何在mysql中的日期格式的月份中减去一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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