Blue Minnie
Blue Minnie

Reputation: 231

Date is not saving the correct value in database

I am currently developing a request page that gets the current date. At first it was working fine and saving the right value into the database, but after I added a code which gets today's week number, the value being saved in my req_date field becomes 0000-00-00. Please help

<?php
$req_date = $_POST['req_date'];

$ddate = date("Y-m-d");
$duedt = explode("-", $ddate);
$date  = mktime(0, 0, 0, $duedt[1], $duedt[2], $duedt[0]);
$week  = (int)date('W', $date);
      
   $sql = "INSERT INTO ops (req_date, week)
            VALUES ('$req_date', '$week')"; 
?>
<td>REQUEST_DATE: </td>
<td><input type="date" name="req_date" value='<?php echo date('Y-m-d');?>'></td>

Upvotes: 2

Views: 370

Answers (1)

Carlos Espinoza
Carlos Espinoza

Reputation: 1175

Chrome can put this format you have to try to use another datepicker set the default format.

Screenshot

This can be a problem if you have a table field with format YYYY-mm-dd and you use that code. You need to improve your code firstly.

Upvotes: 1

Related Questions