Format Dates

Learn how to format dates using Corvid (a.k.a. Wix Code). 

This example shows you how to format a date selected by user input in various ways depending on your preference. Try the example below.

#iptDate
Try it!
dd/mm/yyyy
#txtDate1
#txtDate2
dd month yyyy
#txtDate3
dd mmm yyyy
#txtDate4
#txtDate5
dayname dd mmm yyyy
dayname

Add an onChange event listener for #iptDate to listen for user entry and format the date accordingly. The toLocaleDateString function performs the formatting. The parameter "en-GB" specifies the language format to be Great British English - you can change this to suit your preference. The options parameter specifies the format for the date itself e.g. dd/mm/yyyy or various others. Five date format examples are provided in this example.

Page Code

Please wait ...
Disclaimer: To the best of our knowledge, this code works for its stipulated purpose. If you find an error in our code, or know of a better way to achieve the same result - please contact us! All our code snippets come with full support to help you implement them on your own website - simply contact us for help.