Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a function using Carbon to subtract 1 working day

Tags:

php

php-carbon

Can someone help me with my function, I want my start date to step back one working day but I keep getting Fridays date in the 'start' column of the db if I run the query today, I know its the now() that is doing it can some one point me in the right direction and tell me where to place $start

public function AddNewEvent($title, $start, $end)
{
    try {
        $db = DB();
        $query = $db->prepare("INSERT INTO calendar(title, start, end) VALUES (:title, :start, :end)");

        $query->bindParam("title", $title, PDO::PARAM_STR);
        $query->bindParam("start",$start=Carbon::now()->subWeekdays(1)->toDateString());
        $query->bindParam("end", $end, PDO::PARAM_STR);
        $query->execute();
        return $db->lastInsertId();
    } catch (PDOException $e) {
        exit($e->getMessage());
    }
}
like image 993
Isitabird Avatar asked Dec 05 '25 18:12

Isitabird


1 Answers

I have managed to sort it using parse

$this=Carbon::parse($start)->subWeekdays(1)->toDateString();
like image 58
Isitabird Avatar answered Dec 08 '25 06:12

Isitabird



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!