When working with SharePoint date fields you are offered a Date Picker that let’s you select time to the nearest five minutes.
While this works fine for most tasks and meetings, some manufacturing processes need the time set to the minute.
I first tried some quick JavaScript tricks to change the dropdown list to include 00 to 59, but it appears that the server side code only expects the dropdown to only have five minute steps and that causes an error on save. The next experiment was to create custom New and Edit forms to allow free form edits. Turns out you don’t have to do anything special to the Display form or the views as they just display whatever was entered.
The steps below generally follow what you will find in other blog sites or this MSDN article, expect for replacing the Date Picker fields with Text Box fields.
Test this on a “test” list before duplicating on a production list!
List Preparation
Before we can enter times, you need to configure your list to support Date and Time. Simply go to the list’s properties and edit the date field to support Date & Time.
Also add a Description to your date fields with a sample of an acceptable date. Remember that the user no longer has a date picker to make sure they select a valid date. Something like: “Enter dates as mm/dd/yyyy hh:mm AM/PM”
Disable Attachments!
The following edits will not work if Attachments are enabled for the list. Go to List Settings, Advanced and disable attachments. I think this error is caused by having two web parts on the same page, each adding some common ID that confuses the page’s JavaScript (I did a search and found this article, http://support.microsoft.com/kb/953271, but I did not try it’s solution.)
Fire Up SharePoint Designer!
SharePoint 2007 (and SPD 2007) example follows – 2010 is farther down the page…
Edit the “New” form (NewForm.aspx)
SharePoint 2007 steps:
- Open SharePoint Designer and open your site “http://yourserver/sites/.yoursite”
- In the Folder List expand Lists and your list
- Double-click NewForm.aspx (you may want to make a copy of this file first)
- Display the page in Design view
- Right-click the existing web part and click Web Part Properties
- Expand the Layout section and click Hidden and then click OK
Note: Do not delete the existing web part! - Click below the existing web part (you may need to experiment to find a spot)
- In the menu click Insert, SharePoint Controls and Custom List Form
- Select your list (not just any list with a similar name, your list!)
- Select the correct content type
- Click New Item Form and click OK
- Wait until the fields load
- Click on the date field you want to change
- If the “Common FormField Tasks” popup is not displayed, right-click the web part and select Show Common Control Tasks
- Change the Format As to “Text Box”
- Repeat for any other date fields you need to change (Start Date and Due Date for a task list)
Note: In my test environment, SharePoint Designer 2007 occasionally locks up here. You may have to try this more than once. - Save your changes and click Yes if prompted about “customize a page”.
- Go to a browser and add a new item to the list
Note: Several different date formats are acceptable for date entries:
Edit the “Edit” form (EditForm.aspx)
SharePoint 2007 steps:
- Follow steps 1 – 11 above except double-click EditForm.aspx and select “Edit Item Form”
- If the fields are not displayed:
- Right-click the new web part
- Click Show Common Control Tasks
- click the Show With Sample Data checkbox
- click Refresh Data View.
- Continue with step 13 from above…
You were probably expecting something like this:
and got this instead:
Go back to the EditForm.aspx page, switch to Code view and search for this line (my example uses @StartDate):
<asp:TextBox runat=“server” id=”…” text=”{@StartDate}” …
And then replace @StartDate with
ddwrt:FormatDateTime(string(@StartDate), 1033, 'G')
The result should look like this
<asp:TextBox runat=“server” id=”…” text="{ddwrt:FormatDateTime(string(@StartDate), 1033, 'g')}"
Now test and confirm that it now looks like this:
Edit the “New” form (NewForm.aspx)
SharePoint 2010 steps:
- Open SharePoint Designer and open your site “http://yourserver/sites/.yoursite”
- In the Navigation section click Lists and Libraries
- Double-click your your list
- In the Forms section double-click NewForm.aspx (you may want to make a copy of this file first)
- Display the page in Design view
- Right-click the existing web part and click Web Part Properties
- Expand the Layout section and click Hidden and then click OK
Note: Do not delete the existing web part! - Click below the existing web part (you may need to experiment to find a spot)
- In the Insert ribbon click SharePoint (in the Controls section) and Custom List Form
- Select your list (not just any list with a similar name, your list!)
- Select the correct content type
- Click New Item Form and click OK
- Wait until the fields load
- Click on the date field you want to change
- If the “Common FormField Tasks” popup is not displayed, right-click the web part and select Show Common Control Tasks
- Change the Format As to “Text Box”
- Repeat for any other date fields you need to change (Start Date and Due Date for a task list)
- Save your changes
- Go to a browser and add a new item to the list
Note: Several different date formats are acceptable for date entries:
Edit the “Edit” form (EditForm.aspx)
SharePoint 2010 steps:
- Follow steps 1 – 13 above except double-click EditForm.aspx and select “Edit Item Form”
- If the fields are not displayed:
- Click the “tab” above the new web part:
- Click the Design tab in the Data View Tools section of the ribbon
- click the Sample Data checkbox
- Continue with step 14 from above…
You were probably expecting something like this:
and got this instead:
Go back to the EditForm.aspx page, switch to Code view and search for this line (my example uses @StartDate):
<asp:TextBox runat=“server” id=”…” text=”{@StartDate}” …
And then replace @StartDate with
ddwrt:FormatDateTime(string(@StartDate), 1033, 'G')
The result should look like this
<asp:TextBox runat=“server” id=”…” text="{ddwrt:FormatDateTime(string(@StartDate), 1033, 'g')}"
This edit will display “A.D.” in the Design view, but will display the correct data in the browser.
Now test and confirm that it now looks like this:
Hours, Minutes and Seconds?
SharePoint will store time to the second. There are no additional changes needed for the NewForm.aspx page, and EditForm.aspx only needs the “g” in the FormatDateTime changed to “G”. The real work will be in also creating a custom DispForm.aspx and custom views.
text="{ddwrt:FormatDateTime(string(@StartDate), 1033, 'G')}"
.
10 comments:
Does anyone know if it is possible to add a date picker to a datasheet view on SharePoint? I would like the data picker icon to appear in any of my date fields on the datasheet.
Hello Mike,
thanks for your workaround for this issue. I haven't found any other solution so far online that will not affect the column names or data (as would be in the case of creating a new custom field). I can also confirm that Javascript injection in select box does not work when trying to save.
However, is there a way to have the NewForm pre-filled with the current DateTime? The =Now() formula does not seem to work anymore since the conversion to textbox. So, when a user tries to add a new item he sees an empty textbox instead of the current date/time, which is a show-stopper.
I am using Sharepoint 2010.
Thanks again for providing helpful tip.
Best Regards,
Ari.
Regarding yesterday's email, don't worry, I found the way to pre-fill the textbox with the current date in the new form.
ddwrt:FormatDateTime(string(ddwrt:TodayIso()),1033,'G') does the trick.
I was too tired yesterday that this slipped my attention.
Thanks again.
I have several calculated columns that I have added to my list since making the conversion from date/time picker to textbox. When I go back to view the New Form or Edit Form in SP Designer, it does not display the form fields any more, which incidentally makes it very difficult to make any further changes. Any ideas on why they won't load?
I have several calculated columns that I have added to my list since making the conversion from date/time picker to textbox. When I go back to view the New Form or Edit Form in SP Designer, it does not display the form fields any more, which incidentally makes it very difficult to make any further changes. Any ideas on why they won't load?
Mike,
This is just what the Doctor Ordered!! Thank you for taking the time to detail this out. I have been looking for a work around for this for some time and none have been as helpful as this.
Might be an older post but it still works just fine. Thanks for the tip.
Can someone help. I must have done something wrong...
I follow the instructions but when using the new form and pressing save nothing is saved the form appears to flash off and on but no data is saved.
Does this impact the functionality of a calculation field involving both the start date & time and the end Date & time?
My list is designed to track non-productive times for staff. They provide the time their NP started and ended and the calcuated field populates the mins elapsed between both.
Becca,
This should not change your calculated fields at all.
Mike
Post a Comment
Note to spammers...
Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.