0

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>
2
Contributors
2
Replies
9
Views
3 Years
Discussion Span
Last Post by patk570
0

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!!!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.