Skip to content Skip to sidebar Skip to footer

Jquery Datepicker - How To Change "today" Date?

Is there a way to change the 'today' date in jquery.ui datepicker? With today, I mean today (class='ui-datepicker-today') and not the minDate or the current-selected date! I figure

Solution 1:

Based on the source, it doesn't look good.

var today = newDate();

That is always going to be the user's system date.

If you absolutely must fix this, look down a line; you could override $.datepicker._daylightSavingAdjust and return the date from your server *

But this is a bad idea. Why on earth do your users have their system date so messed up? Why is that your problem? If they complain, tell them to fix their clocks.

* I can't emphasize how bad an idea this is. That function is used to normalize most of the dates in the datepicker, so you'll have to write some pretty convoluted logic to keep from messing everything up. That may not even be feasible.

Solution 2:

A small tweak to the selected answer in jQuery UI DatePicker change highlighted "today" date

// Get users 'today' datevar localToday = newDate();
localToday.setDate(tomorrow.getDate()+1); // tomorrow// Pass the today date to datepicker
$( "#datepicker" ).datepicker({
    showButtonPanel: true,
    localToday: localToday    // This option determines the highlighted today date
});

I've overridden 2 datepicker methods to conditionally use a new setting for the "today" date instead of a new Date(). The new setting is called localToday.

Override $.datepicker._gotoToday and $.datepicker._generateHTML like this:

$.datepicker._gotoToday = function(id) {
    /* ... */var date = inst.settings.localToday || newDate()
    /* ... */
}

$.datepicker._generateHTML = function(inst) {
    /* ... */
    tempDate = inst.settings.localToday || newDate()
    /* ... */
}

Here's a demo which shows the full code and usage: http://jsfiddle.net/NAzz7/5/

Solution 3:

Are you looking ot set the default date when the jQuery UI Datepicker is opened?

If so the datepicker has an option to allow you to set this.

Post a Comment for "Jquery Datepicker - How To Change "today" Date?"