获取当前年份和下一个表格mysql [英] Get Current year and next form mysql

查看:69
本文介绍了获取当前年份和下一个表格mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从表中选择各种内容.问题是我只想选择它们是否属于当年和下一年.

Im am selecting various things from a table. The problem is I only want to select them if they belong to the current year and the next year.

我的桌子看起来像这样

标题文本日期

Title Text Date

日期的格式类似于此0000-00-00,格式为日期"

The date is formated like this 0000-00-00 and is in the format "date"

所以问题是我如何才能仅从今年和明年中选择项目?

So the question is how can i select only items from only this year and the next?

示例:年份为2012年,我的表中有旧项目,并且我不想显示它们-我只想从2012年1月1日的第一笔选择,在这种情况下仅从2013年12月31日的最后一年选择当前年份2012年+ 1年.

Example: the year is 2012, I have items in my table that is old and i dont want them to show - I only want to select items from at the first 2012 1 January and last in this case 31 Dec 2013 current year 2012 + 1 year.

非常感谢您的帮助!

推荐答案

SELECT 
  * 
FROM 
  table 
WHERE 
  YEAR(date) = YEAR(CURDATE()) 
OR 
  YEAR(date) = YEAR(CURDATE()) + 1

http://dev.mysql. com/doc/refman/5.1/en/date-and-time-functions.html

这篇关于获取当前年份和下一个表格mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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