如何获得一个月的第一个和最后几天 [英] how to get the first and last days of a given month

查看:98
本文介绍了如何获得一个月的第一个和最后几天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写一个使用月()和year()函数的mysql查询,以显示从某个月份的所有帖子,作为一个Ym-d参数格式发送到我的函数,但是我不知道如何获得给定月份的最后一天。

I wish to rewrite a mysql query which use month() and year() functions to display all the posts from a certain month which goes to my function as a 'Y-m-d' parameter format, but I don't know how can I get the last day of the given month date.

$query_date = '2010-02-04';
list($y, $m, $d) = explode('-', $query_date);
$first_day = $y . '-' . $m . '-01';


推荐答案

你可能想看看 strtotime date 功能。

You might want to look at the strtotime and date functions.

<?php

$query_date = '2010-02-04';

// First day of the month.
echo date('Y-m-01', strtotime($query_date));

// Last day of the month.
echo date('Y-m-t', strtotime($query_date));

这篇关于如何获得一个月的第一个和最后几天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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