Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:02:33+00:00 2026-06-10T00:02:33+00:00

I have a PHP with a JS datepicker for date and time that save

  • 0

I have a PHP with a JS datepicker for date and time that save all the string in this format “19.08.2012 @ 20:18” in a a variable called $date.

If I place this variable directly in the query, it writes “0000-00-00 00:00:00” in the database.
At the moment I have a big black hole in my head, so need help.

How can I write the correct selected date and time in the database?


Sorry I thought not so important, here is the code.

index.php

<script type="text/javascript">
$(function() {
    $("#date").datetimepicker({
        dateFormat:'dd.mm.yy',
        separator: ' @ '
    });
});
</script>

<form action="setting.php" method="post">
 <table>
 <tr>
  <td><label for="date">Date:</label></td>
  <td><input type="text" id="date" name="date"/></td>
 </tr>
</table>
<input type="submit" name="submit" />

setting.php

if(isset($_POST['save_autoresp'])) {
    create($_POST['date']);
    header("Location: admin.php");
    exit();
} else {
    header("Location: index.php");
    exit();
}

functions.php

.......
.......
// Write the fields to the table
$query_create = mysqli_query($link, "INSERT INTO table VALUES (null, '$id', '$date')") or die ('Could not connect: ' . mysqli_error($link));
.......
.......

The date field in teh MySQL database is “datetime”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T00:02:34+00:00Added an answer on June 10, 2026 at 12:02 am

    The date you receive is in a format that MySQL doesn’t recognize. You must first transform it into an accepted date and time literal, then you can pass it to the INSERT.

    This conversion can be done in two ways:

    • You can configure your JS DateTime Picker so that it returns a date as “YYYY-MM-DD HH:MM:SS”.
    • You can do the above conversion in PHP.

    Whichever you’ll choose, stick to the Year-Month-Day format for the dates when saving to the database, so that you won’t get crazy in finding out why “08/02” was considered the 2nd of August instead of the 8th of February.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: php/Mysql query with inserting date fails I have a datepicker code below:
I have PHP scrip that goes like this: if ($cost_frm < $cost){ echo <script
<script type=text/javascript> $(function() { $('#downpayment_date').datepicker({ dateFormat: 'm/d/yy', minDate: new Date(<?php echo $this->y;?>, <?php echo
I have php code that doesn't work anymore $doc = DOMDocument::loadXML($string); $doc->formatOutput = true;
I have php code that puts some values into an Array as follows: $hunter=addslashes($MessageArray[1]);
I have PHP script works without problems, like this : while($row4 = mysql_fetch_array($result4)) {
I have PHP snippets like this ( snippet.php ): <?php $some_param = some_function(); ?>
I have php script that creates a temporary watermark image for users that are
I have php scripts that do things like register, login, upload. I would like
I have these 2 scripts and the problem is that function check is called

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.