PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 3, 2022

[FIXED] Cakephp how to get 1st and last datetime of a month

 February 03, 2022     cakephp, cakephp-4.x     No comments   

Issue

I am trying to get 1st and last datetime by FrozenTime

I have written below function

public function getFristAndLastDate($year,$month)
{
        $time = FrozenTime::now()->setDate((int)$year, (int)$month, 01)->i18nFormat('yyyy-MM-dd HH:mm:ss');

        return [
            $time->startOfMonth(),
            $time->endOfMonth()
        ];
}

After call function I am getting error

Call to a member function startOfMonth() on string

How can I get 1st and last datetime from year and month in cakephp using FrozenTime ?


Solution

Use create function to create a new ChronosInterface instance from a specific date and time.

FrozenTime::create((int) $year, (int) $month);


Answered By - Alimon Karim
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing