user4534337
user4534337

Reputation:

Javascript datetime to inserted in mysqli query

I have a database set up where landing time requires a datetime data type, and I am trying to pull this off using javascript.

The format looks like the following in the database:

0000-00-00 00:00:00

My best attempt have been the following:

$('#landing_time').val(function(){
      var d = new Date();
      return d.getFullYear() + "-" + d.getMonth() + "-" + d.getDate() + " " + d.getMinutes() + ":" + d.getSeconds() + ":" + d.getMilliseconds();
    });

Upvotes: 1

Views: 153

Answers (1)

Julie Sanchez
Julie Sanchez

Reputation: 51

If you are simply wanting to save the time into the database you are better of letting MySQL handle the date by simply inserting NOW() into the database query.

However, you can find the answer to your question here: Format JavaScript Date to yyyy-mm-dd

Upvotes: 1

Related Questions