Comments on: Dealing with the [Today] problem in SharePoint Calculated Fields http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/ No GeekSpeak on SharePoint 2007 WSS and MOSS Fri, 10 Sep 2010 11:28:29 -0400 http://wordpress.org/?v=2.8.6 hourly 1 By: Ceyda http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/comment-page-1/#comment-97652 Ceyda Wed, 01 Sep 2010 15:06:30 +0000 http://www.endusersharepoint.com/?p=3329#comment-97652 Hi Brian, Did you find out a solution to this particular problem?? Thanks Hi Brian,

Did you find out a solution to this particular problem??

Thanks

]]>
By: Ivan http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/comment-page-1/#comment-70313 Ivan Wed, 26 May 2010 01:31:11 +0000 http://www.endusersharepoint.com/?p=3329#comment-70313 Hi Anthony, Thanks for your help, I fixed it. I kept receiving a null value coming from the function at http://www.daniweb.com/code/snippet238772.html. I'm no javascript expert, so I took the part of the function that splits the date in dd/mm/yyyy and create a new variable with the date in mm/dd/yyyy that I parse using the Date.parse function. Great script David, thanks a lot !!!! Hi Anthony,

Thanks for your help, I fixed it. I kept receiving a null value coming from the function at http://www.daniweb.com/code/snippet238772.html. I’m no javascript expert, so I took the part of the function that splits the date in dd/mm/yyyy and create a new variable with the date in mm/dd/yyyy that I parse using the Date.parse function.

Great script David, thanks a lot !!!!

]]>
By: Anthony http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/comment-page-1/#comment-70221 Anthony Tue, 25 May 2010 10:51:37 +0000 http://www.endusersharepoint.com/?p=3329#comment-70221 Hi Ivan, I added the script David referred me to above, in a hidden web part on my list view page. On line 90, I added a +1 to calculate the correct number of days. var dd = (today-d1)/86400+1; Hope that helps ? Hi Ivan,

I added the script David referred me to above, in a hidden web part on my list view page.

On line 90, I added a +1 to calculate the correct number of days.

var dd = (today-d1)/86400+1;

Hope that helps ?

]]>
By: Ivan http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/comment-page-1/#comment-70189 Ivan Tue, 25 May 2010 06:59:28 +0000 http://www.endusersharepoint.com/?p=3329#comment-70189 Hi Anthony, I'm by all means a JS newby and I'm facing the same issue with the date format (DD/MM/YYYY) in Australia. I have tries to include the code from http://www.daniweb.com/code/snippet238772.html but it doesn't work. Do you mind sharing your solution? Thanks, Ivan Hi Anthony,

I’m by all means a JS newby and I’m facing the same issue with the date format (DD/MM/YYYY) in Australia. I have tries to include the code from http://www.daniweb.com/code/snippet238772.html but it doesn’t work. Do you mind sharing your solution?

Thanks,

Ivan

]]>
By: Anthony http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/comment-page-1/#comment-50891 Anthony Wed, 31 Mar 2010 17:23:08 +0000 http://www.endusersharepoint.com/?p=3329#comment-50891 Ya, it's always something :-) I'll investigate and write back if I figure it out. You've been a huge help :-) Ya, it’s always something :-)

I’ll investigate and write back if I figure it out.

You’ve been a huge help :-)

]]>
By: David Petersen http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/comment-page-1/#comment-50888 David Petersen Wed, 31 Mar 2010 17:14:27 +0000 http://www.endusersharepoint.com/?p=3329#comment-50888 That's an interesting problem. Now I wonder if it is in the other date parsing function or if it is still a locale problem. I am not a JavaScript expert by any means. Someone more knowledgeable than me about the JavaScript Date object would be better to answer this question. I suspect that JavaScript gets it's local information from the machine it is running on. You might check your machine to make sure that the local on your machine is set to European date format. Otherwise, I may have reached the end of my JavaScript Date object knowledge! ;) That’s an interesting problem. Now I wonder if it is in the other date parsing function or if it is still a locale problem. I am not a JavaScript expert by any means. Someone more knowledgeable than me about the JavaScript Date object would be better to answer this question. I suspect that JavaScript gets it’s local information from the machine it is running on. You might check your machine to make sure that the local on your machine is set to European date format. Otherwise, I may have reached the end of my JavaScript Date object knowledge! ;)

]]>
By: Anthony http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/comment-page-1/#comment-50868 Anthony Wed, 31 Mar 2010 16:10:39 +0000 http://www.endusersharepoint.com/?p=3329#comment-50868 Excellent! Thank you David, it worked like a charm :-)) There is a small quirk though: it seems to be one day off ... it returns "1 day" for a createDate of the 29th (today being the 31st)., for example and " 2 days" on a createDate of the 28th. thanks again :) Tony Excellent! Thank you David, it worked like a charm :-))

There is a small quirk though: it seems to be one day off … it returns “1 day” for a createDate of the 29th (today being the 31st)., for example and ” 2 days” on a createDate of the 28th.

thanks again :)
Tony

]]>
By: David Petersen http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/comment-page-1/#comment-50854 David Petersen Wed, 31 Mar 2010 15:36:52 +0000 http://www.endusersharepoint.com/?p=3329#comment-50854 Anthony, I believe the problem you are having is related to the line var d1 = Date.parse($(e).text())/1000; I believe that the javascript Date.parse() function is expecting an American date format. You may want to check out the date parsing function at the following URL: http://www.daniweb.com/code/snippet238772.html . They wrote a date parsing function for European date formats. Once you have parsed the date from the text, then all other parts of the code should work. Try this other date parsing routine and let us know if it worked for you. Hope this helps. Anthony,

I believe the problem you are having is related to the line

var d1 = Date.parse($(e).text())/1000;

I believe that the javascript Date.parse() function is expecting an American date format. You may want to check out the date parsing function at the following URL: http://www.daniweb.com/code/snippet238772.html . They wrote a date parsing function for European date formats. Once you have parsed the date from the text, then all other parts of the code should work. Try this other date parsing routine and let us know if it worked for you.

Hope this helps.

]]>
By: Anthony http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/comment-page-1/#comment-50817 Anthony Wed, 31 Mar 2010 11:18:46 +0000 http://www.endusersharepoint.com/?p=3329#comment-50817 David, thanks for the quick reply. I'm only Danish by marriage: but it's a nice country : you should definitely visit sometime :-) As I mentioned in my original mail, changing the way Sharepoint formats date views in the list does seem to solve my problem. However, as far as I can see that setting (Site Settings –> Regional --> “Locale” --> English (United States).) can only be set at site level, and not at the level on the individual list. Or am I missing something? Setting the format at list level would be the simplest solution, if it is possible. Or maybe I could, with javascript, reformat the date, before feeding it to the rest of the script? Does that seem like a reasonable approach? thanks again :-) Anthony David,

thanks for the quick reply.

I’m only Danish by marriage: but it’s a nice country : you should definitely visit sometime :-)

As I mentioned in my original mail, changing the way Sharepoint formats date views in the list does seem to solve my problem.
However, as far as I can see that setting (Site Settings –> Regional –> “Locale” –> English (United States).) can only be set at site level, and not at the level on the individual list. Or am I missing something?
Setting the format at list level would be the simplest solution, if it is possible.

Or maybe I could, with javascript, reformat the date, before feeding it to the rest of the script?
Does that seem like a reasonable approach?

thanks again :-)

Anthony

]]>
By: David Petersen http://www.endusersharepoint.com/2009/11/09/dealing-with-the-today-problem-in-sharepoint-calculated-fields/comment-page-1/#comment-50608 David Petersen Tue, 30 Mar 2010 20:17:54 +0000 http://www.endusersharepoint.com/?p=3329#comment-50608 Anthony, Denmark is my heritage! Always wanted to go there and look up family that still live there. As for your date issue - I'm afraid that I am not sure how to help your date formatting. In the code, the date functions aren't specific on a format. It uses the standard javascript date object and then parses the date using seconds: For example: var dd = (today-d1)/86400; The only thing I can think of is how you have your date field set up in SharePoint. The code line: var d1 = Date.parse($(e).text())/1000; creates a date object for the date that is stored in the SharePoint date value in the dArray (e). So, once you have the d1 date object, we take today's date (today) and subtract d1. and then divide by 86400 (60 seconds * 60 minutes * 24 hours = 86400 seconds per day). That gives us the number of days from Today. Hope this helps. David Anthony,

Denmark is my heritage! Always wanted to go there and look up family that still live there.

As for your date issue – I’m afraid that I am not sure how to help your date formatting. In the code, the date functions aren’t specific on a format. It uses the standard javascript date object and then parses the date using seconds: For example: var dd = (today-d1)/86400;

The only thing I can think of is how you have your date field set up in SharePoint. The code line:

var d1 = Date.parse($(e).text())/1000;

creates a date object for the date that is stored in the SharePoint date value in the dArray (e).

So, once you have the d1 date object, we take today’s date (today) and subtract d1. and then
divide by 86400 (60 seconds * 60 minutes * 24 hours = 86400 seconds per day). That gives us the number of days from Today.

Hope this helps.

David

]]>