Time

Posted by matman on 26-Sep-2014 09:42

I am trying to retrieve some time values, so I can generate a warning message 5 days after a specific date. My current script to retrieve time:

	var then = "{!web02_materialstime}";
	var toString = "Now #1: " + Date("{!date_field}") + "\r\n";
	toString += "Now #2: " + rbv_api.getCurrentDate() + "\r\n";
	toString += "Now #3: " + new Date() + "\r\n";
	toString += "Then: " + then + "\r\n";
	return toString;
Now #1: Fri Sep 26 2014 09:38:25 GMT-0500 (CDT)
Now #2: Fri Sep 26 2014 14:38:25 (GMT)
Now #3: Fri Sep 26 2014 09:38:25 GMT-0500 (CDT)
Then: Fri Sep 26 2014 19:30:34 (GMT)

Why does the "Then" time field return a date into the future? It's currently setup to " Use current date plus 0 days as default value for newly created records". "Now #2" and "Then" are both GMT, why the difference?

All Replies

Posted by Orchid Corpin on 26-Sep-2014 10:50

Hi matman,

Is the date field "web02_materialstime" hidden or shown in the New and Edit pages and users are free to choose a date?

Thanks,
Orchid

Posted by matman on 29-Sep-2014 04:46

I'm currently running this as a test, so the "web02_materialstime" field is a field that is automatically filled with the time using:

rbv_api.setFieldValue("website3", {!id}, "web02_materialstime", new Date(rbv_api.getCurrentDate()).getTime());

Posted by matman on 29-Sep-2014 06:31

I found out what the problem was. It lies in the storing of a UNIX timestamp ( www.unixtimestamp.com/index.php ) in a date/time field. The timestamp gets converted to match the user's timezone settings. For me that means that when I request a timestamp it lies 7 hours into the future.

I fixed it by just storing "new Date()" instead of "new Date().getTime()". I think it would be a good idea to add some extra information about time handling to the Rollbase user guide? Other than "Using Dates in Formulas" I could find little about it.

Posted by Orchid Corpin on 29-Sep-2014 15:06

Hi matman,

Your suggestions are very much appreciated, feel free to file any ideas in our ideas page below that would help us improve our product including our documentation. https://community.progress.com/community_groups/products_enhancements/i/rollbase/default.aspx

Thank you.

Regards,

Orchid

Posted by matman on 30-Sep-2014 07:20

I encountered a few other problems. When I try storing a rbv_api.getCurrentDate() in a Date/Time field, it returns me "Error: Not a date". When I use Date(rbv_api.getCurrentDate()) it also returns me an error. But when I use new Date(), it is stored succesfully but only as 30/09/2014 6:10 instead of 30/09/2014 14:10 (time difference).

In account settings my timezone is set to GMT+1 (CEST).

Is there any way I could retrieve that stored date, but in the format corresponding to my timezone?

Posted by Orchid Corpin on 30-Sep-2014 11:08

Hi matman,

new Date(rbv_api.getCurrentDate()); -- > Will return current date/time according to what timezone in your Current Rollbase user.
new Date(); -- > Will return current date/time according to your machine's date/time

Hope this may help.

Regards,
Orchid

Posted by matman on 02-Oct-2014 03:03

Works! Thanks for the help!

I ran into another problem regarding time. I now store the time using new Date(rbv_api.getCurrentDate()). I also created a view with filter: "TODAY - 5", but there seems to be a 10 hour difference between that stored Date/Time and TODAY. My "time since contact" formula field returns "5 day(s), 10 hour(s) and 00 minute(s) ago." when I finally see the record in the field. Any way to tackle this problem?

Posted by Orchid Corpin on 02-Oct-2014 17:35

Is the field in TODAY filter does display the correct time and TODAY - 5 displays with 10 hrs? Is it what you mean?

Regards,

Orchid

Posted by matman on 03-Oct-2014 02:46

What I mean is that in my case, TODAY - 5 will never be NOW - 5 days. TODAY only returns the current formatted date (03/10/2014 in my timezone). I'm trying to make NOW - 5 days happen, but the View filter system doesn't allow JavaScript in it's formulas and expressions.

Posted by Orchid Corpin on 06-Oct-2014 13:11

If you want to filter records within 5 days you can use "All (AND)" in the view filter. Field to be filter can be Date/time field and if you are using expression field make sure it does return a Date value.

e.g. View Filters:

1st Row: Created At -------- > less or equal -----------> TODAY

2nd Row: Created At --------> greater or equal -------> TODAY - 5

This thread is closed