Here's the script to do the calculation. You will just need to change the NY_TARGET_DATE constant to whatever date you want.
// The following two constants must be set for your current situation
// NY_TIME_ZONE_DATE_OFFSET = timezone difference between GMT and NY
// NY_TARGET_DATE = the deadline date
var NY_TIME_ZONE_OFFSET = -4;
var NY_TARGET_DATE = "4/8/2010";
var ONE_HOUR_IN_MS = 1000*60*60;
var ONE_DAY_IN_MS = ONE_HOUR_IN_MS * 24;
var nyTimeZoneOffsetMs = NY_TIME_ZONE_OFFSET * ONE_HOUR_IN_MS;
// Obtain target NY date/time as milliseconds
var targetNYDate = new Date(NY_TARGET_DATE);
var targetNYTimeMs = targetNYDate.getTime();
// Get current local date/time from the system as milliseconds
var currentLocalDate = new Date();
var currentLocalTimeMs = currentLocalDate.getTime();
// Get offset of local system timezone from UTC. This
// will be in minutes; convert to milliseconds by multiplying
// by 60000 (60 sec/minute, 1000ms/second)
var localTzOffset = currentLocalDate.getTimezoneOffset() * 60000;
// Add local timezone offset to current local time to convert our local time to UTC
var utcDate = new Date(currentLocalTimeMs += localTzOffset);
// Calculate current NY time by adding NY offset to UTC
var currentNYTimeMs = utcDate.getTime()+ nyTimeZoneOffsetMs;
// Get difference between the target NY date/time
// and current NY date/time in milliseconds
var timeDifferenceMs = targetNYTimeMs - currentNYTimeMs
// Divide by number of milliseconds in a day to get number of days.
// Math.ceil will round up. Will return a positive number of days until
// target date; zero if same day as target date, and
// negative number if past the target date.
var numDays = Math.ceil(timeDifferenceMs / ONE_DAY_IN_MS);
this.rawValue = numDays;
Is there a method for setting the deadline date by the user for your script?
This is due to the changing deadlines based on events.
I am interested in a drop-down date field which will update the deadline date in the script provided.
This script works perfectly by the way, thank you very much.
Yes, not a problem to implement using a date from a dropdown. I'll post an updated script shortly; a little busy now...
Thank you Kevin,
I look forward to the script.
Will you have time to provide the code to modify the deadline date within the script in the next day or two?
Thank you for your time,
I have an updated example but it looks like file attachments have been disabled again. Send me a private message with your email address and I'll forward the example.