How can I change the time portion of a date time column to have 1 minute increments? When you create a coulmn by default it shows 5 minute increments, but I need to be able to use 1 minute increments. For example, I need to be able to pick 12:12, instead of 12:10 or 12:15.
4 Answers
It looks like you are out of luck at least with out of the box datetime field control. A little bit of reverse engineering revealed that they dropdown values are built into the control, not exposed.
You may have to write your own field control.
// Microsoft.SharePoint.WebControls.DateTimeControl private string[] m_minutes = new string[] { "00", "05", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55" }; - 1Or add a content editor web part to your page and override the JavaScript values... :)Russell– Russell2011-12-21 20:21:41 +00:00Commented Dec 21, 2011 at 20:21
- yes, worth trying before writing a new control but not sure if that would conflict with viewstate or the code of the control...Ashish Patel– Ashish Patel2011-12-21 20:23:53 +00:00Commented Dec 21, 2011 at 20:23
- 1The viewstate would contain the value of the DateTime field, which could contain any valid DateTime value. The Validated values (above) would not be in viewstate.Russell– Russell2011-12-21 20:28:04 +00:00Commented Dec 21, 2011 at 20:28
- Do you have a link with a sample of creating a field control?rgwaldron– rgwaldron2011-12-21 20:46:12 +00:00Commented Dec 21, 2011 at 20:46
- 1About creating custom field control you can read here and in addition download some of custom filed controls for sharepoint from codeplex and investigate code (for example this one). Custom field type creation routine for 2010 sharepoint is the same as for 2007Sergei Sergeev– Sergei Sergeev2011-12-22 06:14:50 +00:00Commented Dec 22, 2011 at 6:14
While I have not found a code to replace the 5 minute increments in the time field, I did notice that once the transaction is logged, when you view in spreadsheet mode and click edit, you can then change the time to minute intervals by typing it in and saving. It will hold the time to whatever you type in.
I know it's been years for this question but here is the solution based on jQuery... NOTE: I am not hard-core jQuery expert so, solution may not be clean.
You can edit the forms using SharePoint Designer and add these scripts on them.
The below function basically clears the minute dropdown and adds Minutes values from 0 to 59. You can handle selected values as shown in document.ready event once page is loaded. Multiple controls on the same page are also handled here.
function addOneMinInterval(drpDwn){ drpDwn.empty(); var minItems = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09' , '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59']; $.each(minItems, function(key, value) { drpDwn.append($("<option/>", { value: value, text: value }));//append ends });//$.each ends } $( document ).ready(function() { var minDrp = $("select[id$=DateTimeField_DateTimeFieldDateMinutes]"); for(i=0; i < minDrp.length; i++) { var drpDwnElement = minDrp[i]; var drpDwn = $("#" + drpDwnElement.id); //var optionSelected = drpDwn.val(); var selectedVal = drpDwn.val(); // alert(selectedVal); addOneMinInterval(drpDwn); drpDwn.val(selectedVal); } });//document ready ends