menu

Questions & Answers

Format date events to dd-mm-yyyy in fullcalendar

I have a database, where there dates who are in format like 21-01-2023 but fullcalendar read dates like 2023-01-20.

I would like to read dates events like 21-01-2023 14:55.

I set lang to fr but just change the language not the the format date.

Any advice or tips would be appreciate.

Thanks.

there is example code of what i want to (see the third events example please) the sample code :

<html>
  <head>
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/>
  </head>

  <body>
    <h2>Translate FullCalendar v2</h2>
    <center>
    <div id="calendar"></div>
    </center>
    <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>

    <script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/lang-all.js"></script>

<script>
$(document).ready(function(){
     $('#calendar').fullCalendar({
          lang: 'fr',
                events: [
                        {
                          title: 'All Day Event',
                          start: '2023-01-01'
                        },
                        {
                          title: 'Long Event',
                          start: '2023-01-07',
                          end: '2023-01-10'
                        },
                        {
                          title: 'Long Event in my format date i want',
                          start: '20-01-2023',
                          end: '21-01-2023'
                        },
                ]
      });
});
</script>

  </body>
</html>
Comments:
2023-01-21 23:01:20
in javascript while assigning value you can use str.split('-').reverse().join('-') to change format
2023-01-21 23:01:20
Are the dates in your database stored as strings (varchar)? Or are they stored as DATE or DATETIME? If the latter, they are not stored formatted in a specific way. If the former, convert to the latter.
Answers(0) :