0

I have datepicker

<input class='form-control formBlock datepick' name='period_startdate' value='' type='text' placeholder="Enter First Work Date..." required>

datepicker script

<script>
$('.datepick').each(function(){
    $(this).datepicker();
});
</script>

sql statement

    [other variables...]

    //datepicker variable
    $period_startdate=$_POST['period_startdate'];

    $insertpayperiod= $db->prepare("INSERT INTO payroll (pay_name,pay_group,payday,gross_paycheck,payrate,annual_gross_income,pay_slip_type,pay_rate_unit,total_weekly_hours,total_yearly_hours,created_byid) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
    $insertpayperiod->bind_param("siiiiissiii",$pay_name,$paygroup,$payday,$gross_paycheck,$payrate,$annual_gross_income,$paysliptype,$payrateunit,$total_weekly_hours,$total_yearly_hours,$createdbyid);

MysQl Date format

0000-00-00

How can I convert this to mysql date and make an insert? I have taken notes here. I did read the manual. But while I somehow understand the concept I cant wrap my head around doing it dynamically :-/

Community
  • 1
  • 1
Sebastian Farham
  • 815
  • 2
  • 13
  • 27
  • what mysql date format do you want? What display format do you want? – charlietfl Apr 01 '17 at 23:58
  • When constructing the SQL INSERT, you can supply the string returned by the field, and convert it to a date using the STR_TO_DATE function. Depending on the format returned, this function allows you to specify how to transform it. If you show the SQL statement and the date format you receive in your question above, I can then show you how to format the string – Sloan Thrasher Apr 01 '17 at 23:58
  • @charlietfl: Mysql Date 0000-00-00 – Sebastian Farham Apr 01 '17 at 23:59
  • @SloanThrasher: I updated my question – Sebastian Farham Apr 02 '17 at 00:14
  • @SloanThrasher: I did find something useful here http://www.w3resource.com/mysql/date-and-time-functions/mysql-str_to_date-function.php – Sebastian Farham Apr 02 '17 at 00:22
  • I solved the problem with a solution different from the duplicate page. What they suggested there did not work for me... I solved it with actually formating the datepicker directly with jQuery. – Sebastian Farham Apr 02 '17 at 02:08

0 Answers0