Showing results for 
Search instead for 
Did you mean: 
Showing results for 
Search instead for 
Did you mean: 

Datetime function adding one hour


Datetime function adding one hour


I am having trouble with the following javascript snippet...

var startdate = new Date("01/01/1900");          // returns 1900-01-01 00:00:00.000

startdate.setHours(16);                                    // I expect this will set starttime to 1900-01-01 16:00:00.000

result = startdate;                                             // however, this is what it returns 1900-01-01 17:00:00.000

I don't know why it is adding an extra hour.

And this behavior is only happening for the year 1900. If I instead use the year 1901 or 1899, the script functions as expected.

Some background on why the year 1900 is of interest:

When I query an SQL database from inside ThingWorx, Thingworx is automatically converting SQL's TIME format into ThingWorx's DATETIME format. When it does this, by default the date portion of the datetime is being set to 1900-01-01.

This is a problem as I would like to apply a search filter on the data I retrieve, based on the TIME field i.e.

//    var params = {

//        inclusive: true /* BOOLEAN */,

//        minValue: startdate /* STRING */,

//        t: table1 /* INFOTABLE */,

//        fieldName: "Time" /* STRING */,

//        maxValue: enddate /* STRING */

//    }; var table2 = Resources["InfoTableFunctions"].BetweenFilter(params);

Hence, my startdate and enddate must also be set to 1900-01-01 in order for the BetweenFilter function to work properly

Any suggestions or explanation of this behavior would be really appreciated.



Hi ,

I think you are having TimeZone/Offset problems. Server Javascript it's always executed at Server TimeZone, and your browser visualization ( Composer / Mashup ) it's always rendered at User Browser TimeZone.

Then if you set at Server Side SetHours(16) and and you are trying to view this DateTime from the Browser you may face this kind of "dancing hours".