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!

1
  • See if this answer 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... Commented Oct 14, 2019 at 20:37

2 Answers 2

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');
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.