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 9 years ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
3

answered 9 years ago

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)
Preview: (hide)
link

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  ( 9 years ago )

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  ( 9 years ago )

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

ngkhanh's avatar ngkhanh  ( 9 years ago )

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  ( 9 years ago )

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  ( 9 years ago )

Your Answer

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

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 9 years ago

Seen: 161 times

Last updated: Feb 08 '16