I am having issues updating a simple field in SQL. My Date value once it is in the query wants to do mathematics. It takes the year 2022-03-08 and turns it into 2011 and that is the value it updates the field to. So it takes 2022 subtracts 3 and subtracts 8, and ends up with 2011. Any suggestions what I am doing wrong? I tried several things.
<?php global $wpdb;
$date = new DateTime($nexttargetdate);
$targetdate = $date->format('Y-m-d'); /* This value is example 2022-03-08 */
$table_name = 'Table1';
?>
<script>
alert(<?php echo $targetdate; ?>); /* This value is example 2022-03-08 when alerted */
</script>
<?php
$wpdb->query('UPDATE $table_name SET NEXTTARGETDATE = $targetdate WHERE DOB=%s AND RIGHT(SCRIPT, 4) = %d', $dob, $lastnumb);
/* The $targetdate ends up being a value of 2011 and not the actual date */