-5

I'm trying to call the function deleteMyIdeaDraftRequest with an argument whenever this garbage can image is clicked. However, when I click on the garbage can, I get 'Uncaught ReferenceError: B081517B is not defined'. (B081517B is the draft id I want to pass in)

var idea_draft_id = (current_idea_draft.draft_id).substring(0,8);
var garbageHtml = \"<a> <img class='delete' src='https://d1dxeoyimx6ufk.cloudfront.net/ct/images/c_garbage.gif' title='Delete Draft' onClick='deleteMyIdeaDraftRequest(\"+idea_draft_id+\")'/></a>\";

function deleteMyIdeaDraftRequest(draft_id)
{
BI.ajax_call('ct_xt_delete_my_idea_draft.bix?c=$campaign_id', 'POST', {'draft_id':draft_id}, deleteMyIdeaDraftExecute);
}
coderk
  • 71
  • 12
  • http://stackoverflow.com/questions/6108819/javascript-timestamp-to-relative-time-eg-2-seconds-ago-one-week-ago-etc-best – jeff carey Nov 20 '15 at 23:36

1 Answers1

0

You'd have to convert your date string to a timestamp (milliseconds since 1-1-1970). Then you could do the same to the current date and compare the two (subtracting one from another). With the difference in milliseconds, you can calculate the amount of hours by dividing it by the amount of milliseconds that are in one hour (1000*60*60 = 3600000). You'll want to round that down, so you don't get a long decimal number.

Here's an example: http://jsfiddle.net/4k97au4a/1/

then = Date.parse("2015-11-20T19:56:12+0000");
now = Date.now();
var difference = now - then;
var hours = Math.floor(difference/3600000);
document.write(hours+" hours ago");
Axel Köhler
  • 911
  • 1
  • 8
  • 34