0

I have a datepicker input that i want to fill automatically with the first day of saturday available.

F.E. today is 19/09/2016 i want to show 24/09/2016 in the label of the input

which is the code to add after "defaultdate:" to do so?!

I already set the datepicker to show only the saturday of the month when clicked but the defualt date is locked to the current day.

Clorge32
  • 341
  • 1
  • 3
  • 7
  • Possible duplicate of [jquery datepicker set date to tomorrow's date](http://stackoverflow.com/questions/14591634/jquery-datepicker-set-date-to-tomorrows-date) – MusicLovingIndianGirl Sep 19 '16 at 07:45
  • You can use this script: http://codereview.stackexchange.com/questions/33527/find-next-occurring-friday-or-any-dayofweek – GreyRoofPigeon Sep 19 '16 at 07:47
  • my case is different ... to have the tomorrow's day you just need to add "defaultDate. +1; " in the code – Clorge32 Sep 19 '16 at 08:56

3 Answers3

0

i dont know how can you do in jquery. but i did in c#. if you want to get first monday, tuesday .... of week just use, if you want to get next monday, u can adddays(7).

public DateTime GetNextWeekday(DayOfWeek day)
{
   DateTime result = DateTime.Now.AddDays(1);
    while( result.DayOfWeek != day )
        result = result.AddDays(1);
    return result;
} 
Volkan Sonmez
  • 745
  • 3
  • 14
0

You can get Saturday of this week by below code and set date in date picker which you have used.

var dateObj= new Date();
var numberOfDaysToAdd = 6 - dateObj.getDay();
dateObj.setDate(dateObj.getDate() + numberOfDaysToAdd); 

DatePicker Configuration

$("#datepicker").datepicker({}); 
$("#datepicker").datepicker("setDate", numberOfDaysToAdd );

Check this jsFiddle

Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42
0

I found the prefect solution :

   jQuery('input#date').datepicker('setDate',  get_first_saturday(new Date));
    function get_first_saturday(d) {
        var day = d.getDay();
        var numberOfDaysToAdd = 6 - day;
                firstsaturday= d.getDate() + numberOfDaysToAdd  ;
        return new Date(d.setDate(firstsaturday));
    }
Clorge32
  • 341
  • 1
  • 3
  • 7