jquerydatejquery-uidate-formattingjquerydatetimepicker

How to convert "2020-10-08 09:38:08" into March, 2020 format using jquery


$.datepicker.formatDate('M dd', date)

I have tried this but its giving me error

jquery-ui.js:8924 Uncaught TypeError: date.getDate is not a function


Solution

  • The formatDate method expects a Date instance.

    If you're starting with that particular string, you can easily convert it to ISO 8601 format then parse it into a Date instance

    const date = "2020-10-08 09:38:08"
    const dateInstance = new Date(date.replace(" ", "T"))
    
    const formatted = $.datepicker.formatDate('M dd', dateInstance)