You are viewing limited content. For full access, please sign in.

Question

Question

Date Field Capture Differences in Timezones

asked on January 18, 2017 Show version history

Good Afternoon,

I have users submitting a form in many different time zones. The form is date sensitive (must be completed by end of day in their timezone). I want to have a field on the form that will capture the users date of submission. Will setting the date to today suffice or will I have to use Javascript? Any help with the Javascript, if required, would be greatly appreciated!

 

Thanks

0 0

Answer

SELECTED ANSWER
replied on January 18, 2017 Show version history

Your basic method to get the current date is to use a date field in your form and set the default value to today - but unless I'm mistaken, that will use the server's date (*EDIT - process time zone configured *), not the user's datetime.

To use the current datetime from the end user's machine in Javascript, you only need to declare a date object without passing a value, like this: Date()

This should return the full datetime value for the user's local machine.  Try testing it by changing your machine's time zone and this Javascript (which populates the value into a Single Line field with CSS Class of singleLineField - real original, I know):

$(document).ready(function () {
  var myDate = Date();
  $('.singleLineField input').val(myDate);
});

Of course, this will return the full datetime with time zone detail (i.e. "Wed Jan 18 2017 20:35:09 GMT-0700 (Mountain Standard Time)").
If you want to break it up, you can use formulas like this, which populates the date into a date field which has a CSS Class name of dateField (almost as original as the last one):

$(document).ready(function () {
  var myDate = new Date();
  var m = myDate.getMonth()+1;   //month (add 1 because JS defaults months 0-11)
  var d = myDate.getDate();   //day of the month
  var y = myDate.getFullYear();   //4-digit year
  $('.dateField input').val(m + '/' + d + '/' + y);
});
0 0
replied on January 19, 2017

Clarification, the default value of today will follow process time zone configured.

0 0
replied on January 20, 2017

Yes, that would make more sense than server time.  Thanks!

0 0
replied on December 21, 2020

If the deadline is 5 p.m. instead of midnight, what is the next step to compare it with the local time returned from the Date function?

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.