jQuery UI DatePicker - Change Date Format

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for jQuery UI DatePicker - Change Date Format

jQuery UI DatePicker - Change Date Format 💡

So, you're using the UI DatePicker from jQuery UI and you're having trouble getting the date returned in the format you want. No worries, I got you covered! 😎

First, let's understand the problem. By default, when you call getDate() on a DatePicker instance, it returns the date in the format Tue Aug 25 2009 00:00:00 GMT+0100 (BST). But you want it in the format DD-MM-YYYY. Let's see how we can achieve that.

Solution 🛠️

The jQuery UI DatePicker provides a dateFormat option that allows you to specify the format you want the date to be returned in. Simply set the dateFormat option when initializing the DatePicker:

$("#datepicker").datepicker({
  dateFormat: "dd-mm-yy" // Specify your desired date format here
});

In this case, we set dateFormat to "dd-mm-yy". This means the date will be returned in the format DD-MM-YYYY. Easy, right? 😉

Now, when you call getDate(), the date will be returned in the format you specified.

var date = $("#datepicker").datepicker("getDate");

And voila! You'll get the date in the format you wanted 🎉

Additional Options 🌟

The dateFormat option provides more flexibility to customize the date format. Here are a few common format options:

  • d - day of the month (no leading zero)

  • dd - day of the month (with leading zero)

  • m - month (no leading zero)

  • mm - month (with leading zero)

  • yy - year (two-digit)

  • yyyy - year (four-digit)

Feel free to mix and match these options to customize the format according to your needs.

Have Fun Customizing! 🎉

Now that you know how to change the date format in the jQuery UI DatePicker, go ahead and customize it to your heart's content! Play around with different format options and find the one that suits your application best. And don't forget to share your cool date picker creations with me! 🌈

If you found this guide helpful, don't hesitate to share it with your fellow devs. Together, we can make the date pickers of the world look cooler than ever before! 🚀

Got any questions or other jQuery UI DatePicker dilemmas? Leave a comment below or hit me up on social media. Let's chat about date pickers! 💬

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my