Question-and-Answer Resource for the Building Energy Modeling Community
Get s tarted with the Help page
Ask Your Question

Date syntax in OS API

asked 2016-02-07 12:52:17 -0500

ngkhanh gravatar image

Hello, i would like to know how input begin and end date to get the number day of a time period ? I got the month and day as integer values (day -1, month -1) but have problem when convert them to date format in OS for date calculation

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-08 01:36:23 -0500

Take a look at the Time section on this page of the SDK documentation. For dates and time, OpenStudio has the following:

Now let's say that you want to create a date. The "tricky" part is that for the month it requires an OpenStudio::MonthOfYear:

day = 1
month = 1
year = 2010
date =, day, year)
edit flag offensive delete link more


@Julien Marrec Thank a lot. After those definition, may i use date1 - date 2 to get the day number between 2 date ? Have any special syntax should be consider ?

ngkhanh gravatar image ngkhanh  ( 2016-02-08 05:11:37 -0500 )edit

Yes. it seems to return an OpenStudio::Time (t = date1-date2), on which can call for example t.totalDays to get a float (decimal number) of the number of days.

To know this kind of stuff I usually just open a command prompt or terminal, launch ruby and require openstudio, and then I can explore and try things like this.

Julien Marrec gravatar image Julien Marrec  ( 2016-02-08 06:03:52 -0500 )edit

May i do it in ruby console of sketchup ? ruby IDE installation with Openstudio is too complicated.

ngkhanh gravatar image ngkhanh  ( 2016-02-08 10:58:28 -0500 )edit

You should be able too yes. But there's nothing complicated to install ruby to work with openstudio though. See the beginning of this page, section Optional - Install ruby

Julien Marrec gravatar image Julien Marrec  ( 2016-02-08 14:23:51 -0500 )edit

i did it but i did not see the advantages of ruby installation when compare with notepad++ and Apply Measure Now. The main advantage is test console but i don't know much about this. Most of time the measure test is collapsed - Please give some suggest if you got a good installtiopn ruby.

ngkhanh gravatar image ngkhanh  ( 2016-02-08 14:47:17 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer


Question Tools

1 follower


Asked: 2016-02-07 12:52:17 -0500

Seen: 104 times

Last updated: Feb 08 '16