Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Datepicker: Show one date format to user, use another date format in the background

I've got an input using the datepicker tool from jQuery. Now I know I can set the date format being used by the datepicker. Problem is: I'd like to show the date in the german format to the user, while using the english format for the database (dd-mm-yy to yy-mm-dd).

What I have here now is the following:

$(".date").datepicker({
    dateFormat: "dd-mm-yy",
    onSelect: function(dateText, inst) {
        $("#test").html($.inst.formatDate('yy-mm-dd', dateText); // What exactly do I have to do, to get the date from dd-mm-yy to yy-mm-dd
    }
});
like image 716
Ahatius Avatar asked Feb 18 '23 05:02

Ahatius


1 Answers

Probably your best option is to use altField and altFormat properties for the datepicker, which are there exactly for this reason: API Docs.

If you set the altField to an hidden input field, you can then get the data from there when uploading to the DB or for anything else you need the alternate date format.

like image 176
Tallmaris Avatar answered Feb 21 '23 03:02

Tallmaris