My goal is to pull a value on the EditForm from a Date field. I want to take the 'due date' field, do a "get date", and subtract the difference between that date and today to get a "days left" number. I don't think the last part will be difficult since I'm fairly familiar with javascript, but the getFieldValue with the four parameters method isn't returning anything. Is there a better method to choose?

Well, I tried....

var myDate = //

......but that won't work because it's not a single line of text.

I tried:

var theDate = getFieldValue('Due Date','','; ','');
  • Can you post some of the code that you've tried, it will help us debug it – udog Feb 14 '14 at 20:57
  • done "Due Date" is the name of my date column by the way. – user3299197 Feb 14 '14 at 21:48
  • is "alert(Due Date);" a typo -- did you mean "alert(colDate)"?; also, can you post an HTML snippet (portion of tags near and including the input) – udog Feb 14 '14 at 21:56
  • Yes, that was a typo. Sorry! The only html I have are the two references to jquery and spservices files and everything enclosed in the html and script tags. Should I have more? @udog – user3299197 Feb 15 '14 at 2:19

I'm not sure that I understand your difficulty. I used your jQuery above in the following way:

<input type="text" 
       title="Due Date" 
       class="ms-input" autopostback="0">

//I typed this into the console. I use Moment.js for most of my date-time work.
var myDate = new Date( $("input[title='Due Date']").val());
var timeLeft = moment(myDate).fromNow();
console.log("This item is due " + timeLeft + ".");

And got this:

enter image description here

Injected into my page via

var myDate = new Date( $("input[title='Due Date']").val());
var timeLeft = moment(myDate).fromNow();
$("#time-left").text("This item is due " + timeLeft + ".");

enter image description here

So your code should work just fine!

  • Ah my issue was that I was retrieving the date value incorrectly. Thank you for your help! – user3299197 Feb 17 '14 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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