0

I'm using jQuery date picker. How do I save the selected date value to a SQL date field in the database. And how do I retrieve the date value from the database and have it select the date in the picker?

I find the documentation is scarce for this library.

Thanks in advance!

John Smith
  • 465
  • 1
  • 4
  • 18
  • See if this [answer](https://stackoverflow.com/questions/20083807/javascript-date-to-sql-date-object#answer-21482470) helps. It looks like from the docs that a JavaScript `Date()` object is returned from the _jQuery UI_ `getDate()` method. As such, you'll need to complete the conversions manually to _SQL_ and back again... – War10ck Oct 14 '19 at 20:37

2 Answers2

1

If you use PHP between jquery and DB you can do manually conversion with:

//Create Date object from a specified format
$date = DateTime::createFromFormat('d/m/Y', $_REQUEST["dateFromPicker"]);

//From date Object to a specified format String
$str = $date->format('Y-m-d');

In JS/JQuery you can use the moment library to help:

//Create moment object from a specified format
var date = moment(dateVal, 'DD/MM/YYYY');

//From moment Object to a specified format String
var str = date.format('YYYY-MM-DD');
0

you can't use jquery to save to the database directly unless you are using node.js

you have to send the date to php file and from the php to the database

Andrew Nic
  • 108
  • 1
  • 11