SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to retrieve selected date on add event in sharepoint Calendar ??

share|improve this question
I also facing same problem... Any suggestion? – Viraj Gorajia Sep 29 '12 at 9:10
Are you talking about event receiver and want to retrieve the date on ItemAdd ? – Arsalan Adam Khatri Sep 29 '12 at 13:24
I want to retrieve date on add click event in Calendar – Rajesh Joshi Oct 1 '12 at 4:39

When you click on "Add" in SharePoint Calender, the "Start Time" column will give you the current selected date. You can also create a calculated field called "Selected Date" and get it populated with only date part of "Start Time" column through formula.

share|improve this answer
up vote 0 down vote accepted

this link is helps to find out selected date in sharePoint calendar

The selected date in a SharePoint 2010 calendar may be needed when writing custom solutions. This can be retrieved using JavaScript and jQuery. First, we need to determine if we are in the month, week, or day scope of the calendar. There is probably a better way to do this, but the following seems to work:

// make these global
var selectedDate = 'no date selected';
var selectedTime = 'no time selected';

// put the rest of the code in a function
function GetSelectedDate() {

  var dayScope = $('');
  var weekScope = $('');
  var monthScope = $('');

  var isDayScope = dayScope.length > 0 ? dayScope.attr('summary').indexOf('Daily') > -1 : false;
  var isWeekScope = weekScope.length > 0 ? weekScope.attr('summary').indexOf('Weekly') > -1 : false;
  var isMonthScope = monthScope.length > 0 ? monthScope.attr('summary').indexOf('Monthly') > -1 : false;

  var selecteddateelement = $('.ms-acal-vitem');

  if(isMonthScope) {
   var tditem = selecteddateelement.parent();
   var tritem = selecteddateelement.parent().parent();
   var prevtr = tritem.prev();
   var indx = tritem.children().index(tditem) + 2;
   var dttd = prevtr.children(':nth-child(' + indx + ')');
   if(selecteddateelement.length > 0) selectedDate = dttd.attr('date');

  else if(isWeekScope) {
   var weektritem = selecteddateelement.parent();
   var weekdayindx = weektritem.children().index(selecteddateelement) + 1;
   var weekselectedhalfhourstarttime = $('[class^=ms-acal-hour]').index(weektritem) / 2;
   var weekdttd = $('.ms-acal-week-top').children(':nth-child(' + weekdayindx + ')');
   if(weekdttd.length > 0) selectedDate = weekdttd.attr('date');
   if(weekselectedhalfhourstarttime >= 0) selectedTime = weekselectedhalfhourstarttime;

  else if(isDayScope) {
   var verbosedaydate = $('.ms-acal-display').text();
   var daydatesplit = verbosedaydate.split(/,| /);
   var month = daydatesplit[1];
   var dayscopemonth = (new Date()).getMonth() + 1; // default to current month

   if(month == "January") dayscopemonth = 1;
   else if(month == "February") dayscopemonth = 2;
   else if(month == "March") dayscopemonth = 3;
   else if(month == "April") dayscopemonth = 4;
   else if(month == "May") dayscopemonth = 5;
   else if(month == "June") dayscopemonth = 6;
   else if(month == "July") dayscopemonth = 7;
   else if(month == "August") dayscopemonth = 8;
   else if(month == "September") dayscopemonth = 9;
   else if(month == "October") dayscopemonth = 10;
   else if(month == "November") dayscopemonth = 11;
   else if(month == "December") dayscopemonth = 12;

   var dayscopeday = daydatesplit[2];
   var dayscopeyear = daydatesplit[3];

   selectedDate = dayscopemonth + '/' + dayscopeday + '/' + dayscopeyear;

   var daytr = selecteddateelement.parent();
   var dayselectedhalfhourstarttime = $('[class^=ms-acal-hour]').index(daytr) / 2;
   if(dayselectedhalfhourstarttime >= 0) selectedTime = dayselectedhalfhourstarttime;

Now the selectedDate and selectedTime will be populated.  Echo these to the console to see the values:

  console.log("selectedDate:    " + selectedDate); // change this to do something with the date
  console.log("selectedTime:    " + selectedTime); // change this to do something with the time
  // end the function

The selectedDate and selectedTime variables should be global variables.  This allows the preceding code to be put into a function, say "GetSelectedDate()" and bound to a click event on the calendar.  The issue with not doing this is if you are trying to call this code from a button or anchor click outside of the calendar, when clicked, first the calendar looses focus, then the ms-acal-vitem class is stripped.  The result is that nothing is selected when the code would run, coming back with "no date selected" every time.  Binding to click would look like this:

$(document).ready(function () {
 $('.ms-acal-rootdiv').unbind("click").click(function () {

Doing so will set the global variables selectedDate and selectedTime every time a click is made. Another thing you may want to do is create a function to set these variables to the current date and time. This could be called first, then the preceding code, resulting in selectedDate and selectedTime always having a date populated.

It seems like a long way to go to get the selected date, and does not handle localization. I would love to see what others are doing to solve this issue. I know there are some xslt solutions out there too.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.