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

Date syntax in OS API

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

ngkhanh's avatar

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
3

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 = OpenStudio::Date.new(OpenStudio::MonthOfYear.new(month), day, year)
edit flag offensive delete link more

Comments

@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's avatar 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's avatar 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's avatar 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's avatar 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's avatar 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

Careers

Question Tools

1 follower

Stats

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

Seen: 132 times

Last updated: Feb 08 '16