duanrang2627 2017-10-02 10:34
浏览 42
已采纳

如何从给定的数字月份PHP获取该月的第一个和最后一个日期

I want to get the first date and last date of the month if given I have a numeric number of the month.

For example January = 01, October = 10, November = 11

So if I pass 10 as parameter I should get the first and last date of October.

I tried to implement it using Carbon. But I gives me different result.

Here is the code. The result is is next to it.

$dt =  Carbon::create(10);
echo $dt->startOfMonth(); // 0010-10-01 00:00:00
echo $dt->endOfMonth(); // 0010-10-31 00:00:00
  • 写回答

2条回答 默认 最新

  • doula2426 2017-10-02 10:37
    关注

    The first day of any month is the first.

    use createFromFormat

    $dt = Carbon::createFromFormat('m', 10);
    echo $dt->endOfMonth();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料