Hi, I have 2 fields that are used for date. In my fucntion, i have it format the date into Y-m-d format,

$purchase_date = mysqli_real_escape_string($mysqli,date('Y-m-d',$_POST['purchase_date']));
$warranty_end_date = mysqli_real_escape_string($mysqli,date('Y-m-d',$_POST['warranty_end_date']));

But when I enter a date into it, it just puts 0000-00-00

I thought this was the correct format, but seems to not work.

I did try this as well:

$purchase_date = mysqli_real_escape_string($mysqli, date('Y-m-d', strtotime(str_replace('-','/',$_POST['purchase_date']));
$warranty_end_date = mysqli_real_escape_string($mysqli, date('Y-m-d', strtotime(str_replace('-','/',$_POST['warranty_end_date']));

but didnt work either.

Here is the form elements as well:

<div class="form-group">
    <label for="purchase_date">Purchase Date</label>
    <input type="text" name="purchase_date" class="form-control" id="purchase_date" placeholder="Purchase Date">
</div>
<div class="form-group">
    <label for="warranty_end_date">Warranty End Date</label>
    <input type="text" name="warranty_end_date" class="form-control" id="warranty_end_date" placeholder="Warranty End Date">
</div>

Recommended Answers

All 2 Replies

print out your $_POST date what format is the date in

date field or datetime field?

I figured it out:

$purchase_date = mysqli_real_escape_string($mysqli, date('Y-m-d', strtotime(str_replace('-','/',$_POST['purchase_date']));
$warranty_end_date = mysqli_real_escape_string($mysqli, date('Y-m-d', strtotime(str_replace('-','/',$_POST['warranty_end_date']));

worked, just forgot to upload it to the server. I thought it was uploaded haha!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.