TODAY function
-
Monday, May 12, 2008 6:57 PM
I am trying to set the default value for a text field to a formatted string made up of date and time values but I have been unsuccessful at getting the current time from the TODAY function. it does not seem to return the time portion of the current date/time.
If you set the default value of a text field to be =text(today,"mm-dd-yyyy h:mm
s") you will see "05-12-2008 0:00:00"=YEAR(Today)
=MONTH(Today)
=DAY(Today)
all return the correct information but
=HOUR(Today)
=MINUTE(Today)
=SECOND(Today)
All return blank
How can I get the current time?
Thanks
All Replies
-
Monday, May 12, 2008 8:13 PMWhy not make it a date field instead of a text field? Then you have the option to set the default value to today's date & time.
-
Monday, May 12, 2008 8:22 PM
Because the objective is to generate a reference or document ID made up of text, date and time information such as:
2008-IT-34568.45689.
But, regardless of how this is to be used, the question remains: how to obtain the current time such as a VB now() function.
-
Monday, May 12, 2008 8:54 PM
By default, TODAY does not return the current time, as you have found.
By using SharePoint designer you can use the IncludeTimeValue attribute to return date and time. I describe how to do this here: http://nickgrattan.wordpress.com/2008/04/24/filtering-views-by-time-and-date/.
You should be able to apply this information to solve your problem.
Regards,
Nick Grattan
________
Blog: http://nickgrattan.wordpress.com
Web: http://www.nickgrattan.net
-
Tuesday, May 13, 2008 12:54 PM
I had already seen your workaround for filtering views by time - very clever. But, in this case it doesn't apply because I am talking about getting this information at item creation time and I cannot alter the default new item webpart.
I could possibly create a custom list item form in Designer but the solution would be limited to the library and thos created from its template.
Isn't this a bug with TODAY? Afterall the description does say it returns a date-time serial.
-
Tuesday, May 13, 2008 1:29 PM
Looks like I answered a different question!
The "Created" column has the date/time stamp of when the item was created. Can you create a workflow that's automatically executed when the item is created and then take the "Created" column value and format this as required and then copy into your text field?
Nick.
-
Tuesday, May 13, 2008 3:55 PM
That would work except the user would never see it until they save the document and then edit the properties again. Sort of defeats the purpose of a default value.
I am thinking I may need to create a custom list form where I have more control over the fields and can actually include scripts to take care of stuff like that.
It seems a pitty that such basic stuff like that slips through the cracks.
-
Wednesday, May 14, 2008 7:57 AMOK, I see your problem now. Yes, a custom list form is probably the way forward so best of luck! Nick.
-
Wednesday, May 14, 2008 7:20 PM
Well Nick,
you did put me down the right path.
I have implemented a solution which ends up being much more robust than what I was aiming for- that is a good thing.
I modified my EditForm.aspx adding a variation of the code you pointed to and it now fills in my document ID with the year and serial number (2008-12345678901).
The problem now is that it only works when I edit a document's properties or upload a document to the document library.
It is completly ignored when I save a Word 2003 document to the document library. The "Web File Properties" dialogue that comes after saving the file seems to be a different animal alltogether called from Word with this URL:
http://portal.mycompany.com/_vti_bin/owssvr.dll?location=Documents/MyDoc.doc&dialogview=SaveForm
Any ideas on how to make that form/dialogue be the same as the EditForm.aspx I already customized?
Thanks,Code Snippet<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("fillDefaultValues");
function fillDefaultValues() {
// setLookupFromFieldName("<<FIELD DISPLAY NAME>>", vals["<<QUERYSTRING VARIABLE NAME>>"]);
mdate = new Date; //Current Datemdate1= new Date; //date for begining of year
mdate1.setFullYear(mdate.getYear(),"0","01");
mdate1.setHours("0","0","0","0");
var mid=(mdate.getYear()+"-"+(mdate.getTime()-mdate1.getTime()));setTextFromFieldName("DocumentID",mid);
setFieldReadOnly("DocumentID", true)
}function getTagFromIdentifierAndTitle(tagName, identifier, title) {
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++) {
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
return tags[i];
}
}
return null;
}
function setTextFromFieldName(fieldName, value) {
if (value == undefined) return;
var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
if (theInput.value == "" || theInput.value == undefined){
theInput.value=value
}
}
function setFieldReadOnly(fieldName, value) {
if (value == undefined) return;
var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
theInput.readOnly=value;
}</script>

