I want format from string to date. How can i do?

public function checkTimeCourse(){

    $modelCoure = Mage::getModel('course/courses')->getCollection();
    $toDay = date('Y-m-d');echo $toDay; //2020-05-19
    foreach($modelCoure as $item){
        $dateTo = date($item->getDateTo()); // select from database string(2020-05-25)
        $checkDay = $toDay - $dateTo;

Help me please!


You can try the strtotime() function

| improve this answer | |
  • Yes i have try but it will output int(1590362780) – Hưng Nguyễn May 19 at 1:56
  • And i try date('Y-m-d',strtotime($item->getDateTo())); but it output int(0) – Hưng Nguyễn May 19 at 1:57
  • if you dump $item->getDateTo() what is the output? – fmsthird May 19 at 2:46
  • if i dump it will output string(10) "2020-05-25" – Hưng Nguyễn May 19 at 2:52
  • 1
    Yes right. I want do it.. – Hưng Nguyễn May 19 at 4:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.