-1

I am using a bootstrapdatetimepicker as well as moment.js

When i call the following

var starteventtime= ($('#startdatetime').data('DateTimePicker').date());

I get a date similar to

Wed Mar 27 2019 00:00:00 GMT+0000

I also have the option for the user to save their own format of the date. So any code will have to take this into consideration.

<?php
   $datetimeformat = 'DD/MM/YYYY HH:mm';
 ?>
    $(function() {
             $('#startdatetime').datetimepicker({
             format: '<?php echo $datetimeformat; ?>'
    });

How do i parse this on the client side with javascript to get Mysql formatted date so when the data is serialized it will be in a format ready for insertion into the database like below

2019-03-27 00:00:00
Ryan
  • 129
  • 9

3 Answers3

0

I am quite certain whatever the date time picker returns is a Date object and not a string (if it isn't, use another picker, because this one is useless).

When you have the Date object, you can format that however you want to insert it into your database. For example with the answer given here: How to format a JavaScript date

Bart Friederichs
  • 30,888
  • 13
  • 85
  • 169
0

You should look into converting your dates into a standard Unix timestamp. Its super easy in every environment you're working in (Mysql, php, javascript). For example, in javascript Date.now() returns the current time as a Unix timestamp. Look up how to do that for the other places you're working with time. With that as a standard, you can just pass around the timestamps for your dates without having to worry about formatting until you're ready to display them.

Geuis
  • 37,442
  • 53
  • 145
  • 213
0

Thanks for the advice , i used

moment($('#startdatetime').data('DateTimePicker').date()).format("YYYY/MM/DD HH:mm"));

to convert it to an object that was in mysql format.

Ryan
  • 129
  • 9