怎么样取出mysql中某月份的记录?

echolife 2009-03-01 03:08:02
表A,

ID startdate
-----------------------------------
1 1213459200
2 1213632000
3 1213459200
4 1213632000
5 1213459200
6 1213632000


取出某年某月的记录,比如2009年5月的所在记录,或者其它年月月的。
...全文
243 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wfnychuan 2009-08-03
  • 打赏
  • 举报
回复
select * from a where from_unixtime(startdate,'%Y%m')='200805';
hqaht 2009-03-02
  • 打赏
  • 举报
回复

select * from Table where startdate between UNIX_TIMESTAMP('2009-5-1 00:00:00') and UNIX_TIMESTAMP('2009-5-30 00:00:00')
//2楼正解,但还是有点不完美,修改一下,也可以用dateformat格式化日期,然后substr,这样很麻烦,所以建议楼主还是使用2楼的方法吧
dzxccsu 2009-03-02
  • 打赏
  • 举报
回复
select * from Table where startdate between UNIX_TIMESTAMP(2009-5-1) and UNIX_TIMESTAMP(2009-5-30)
yctin 2009-03-02
  • 打赏
  • 举报
回复
嗯~楼上的可以了
开始结束时间可以在pgp计算
阡陌红茶 2009-03-02
  • 打赏
  • 举报
回复
string date ( string format [, int timestamp] )
date("Ymd",$startdate);
可以从数据库中先把时间数据读出来用date("Ymd",$startdate)转换成正常的时间格式,然后再比较。
liuyang1588 2009-03-02
  • 打赏
  • 举报
回复
MYSQL还是瞒好用的 呵呵

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧