Time zone ignored when getting date

Posted by Rollbase User on 19-Jul-2010 19:44

My time zone in personal preferences, and company preferences is set to GMT+10. When I create a new date in Javascript, it seems to ignore the time zone and return yesterday's date. See attached picture - today is Tuesday in Australia.

All Replies

Posted by Admin on 19-Jul-2010 21:21

I don't think we can help with that. JavaScript Date object provides limited TimeZone -specific functionality. Please check http://www.w3schools.com/js/js_obj_date.asp for more details.

Posted by Admin on 19-Jul-2010 22:47

Pavel, are you saying that if I want to use Rollbase, I need to be in your time zone? Why is there a time zone setting in my preferences? Maybe you can have a API call GetLocalTime() which gets your time, compares timezones, and returns the local time? There are many saas systems that operate across time zones -- there must be a way to return the correct date?

Posted by Admin on 20-Jul-2010 11:48

What exactly seems to be the problem? There is one clock in the system (on server), but when it comes to displaying date and time resulting string is formatted according to user's time zone and selected format. In JavaScript API this should work the same way.

The fact that Date is using CDT should not concern you - this is for intermediate operations only. When it comes to actual display you should see correct result.

Posted by Admin on 20-Jul-2010 18:05

Maybe I'm looking at it wrong. I have a formula that looks like this:



if("{!status#value}" != "Outstanding")

return 4;

dt = new Date("{!due_date}");

today = new Date();

if(dt.getDate() == today.getDate())

return 2;

if(dt

return 1;

if(dt > today)

return 3;



the problem is that today is being assigned yesterday's date, so the wrong integer is being returned.

Posted by Admin on 20-Jul-2010 18:46

Actually, I just checked your rollbase formula guide, and the way you get your dates is exactly the same. This means that many of the date formulas in your guide will not work in different timezones. For example:



Days until a target date

This formula calculates the number of days between two dates and returns a String. If the target date is given by

the merge field {!targetdate}, the number of days can be calculated as follows:

var today = new Date();

var targetdate = new Date("{!targetdate}");

remaining = ((targetdate.getTime() - today.getTime()) / (24 * 60 * 60 * 1000));

remaining = Math.round(remaining);

return remaining + " days left";



this will not work because today variable is assigned yesterday's date, so remaining ends up 1 more than it should. Does this make sense?

Posted by Admin on 20-Jul-2010 21:48

Good point. We'll provide server-side API which will generate JavaScript Date object taking into account user's time zone.

Posted by Admin on 20-Jul-2010 21:49

terrific. thank you.

Posted by Admin on 04-Aug-2010 03:06

Hi Pavel. Did you implement this one yet?

Posted by Admin on 04-Aug-2010 10:47

The example above works fine for date/time values (I tried) since date/time is re-calculated to server time zone, so the difference is correct. However for date only value there may be a problem. I will need to provide an API for that.

Posted by Admin on 04-Aug-2010 23:53

I finally figured out (I think) how to deal with this issue. The following code should work:

var today = new Date(rbv_api.getCurrentDate());
var targetdate = new Date("{!targetdate}");
remaining = ((targetdate.getTime() - today.getTime()) / (24 * 60 * 60 * 1000));
remaining = Math.round(remaining);
return remaining + " days left";


API getCurrentDate generates a text string corresponding to current date and user's time zone. Field dates should include correct time zone as well, so no API is needed. Please try at your convenience. I'm updating documentation (Chapter 6).

This thread is closed