Knowledge Base

Change the date format on booking forms

By default, the booking form on all of our themes uses the “YYYY/MM/DD” notation. In this article, we will see how this can be modified.

You will need to start by navigating to the /js  folder of the theme. In there you will find the scripts.js file (on a couple of themes this might be named ci_scripts.js of jquery.scripts.js) and edit it.

Locate this line

dateFormat: 'yy/mm/dd',

and modify it to

dateFormat: 'dd/mm/yy',

or

dateFormat: 'mm/dd/yy',

according to your preference.

Notice: this line appears twice a few lines apart, change them both.

Next, we need to reconfigure the validation.

Edit the template-booking.php file located in the main theme folder and locate these bits of code

if(!checkdate(substr($arrive, 5, 2), substr($arrive, 8, 2), substr($arrive, 0, 4)))

and

if(!checkdate(substr($depart, 5, 2), substr($depart, 8, 2), substr($depart, 0, 4)))

if you used the dd/mm/yy format, you will change them to

if(!checkdate(substr($arrive, 3, 2), substr($arrive, 0, 2), substr($arrive, 6, 4)))

and

if(!checkdate(substr($depart, 3, 2), substr($depart, 0, 2), substr($depart, 6, 4)))

respectively, if you used the mm/dd/yy format, you will change them to

if(!checkdate(substr($arrive, 0, 2), substr($arrive, 3, 2), substr($arrive, 6, 4)))

and

if(!checkdate(substr($depart, 0, 2), substr($depart, 3, 2), substr($depart, 6, 4)))

respectively.

When the changes are made you can save the file and you’re done.