|
GAMS contains a number of functions that may be used to do things involved with times and dates. The fundamental measurement of time in GAMS is the sequential day number since January 1, 1900, where the integer part of this number contains a unique number for each day while the fractional part contains information about hour, minute, second etc. The day numbers are based on the Gregorian calendar.
In the following table the Endogenous Classification (second column) specifies in which models the function can legally appear. In order of least to most restrictive, the choices are any, NLP, DNLP or none. Note that constant arguments are required.
Function
|
Endogenous
Classification
|
Description
|
gday(SDAY)
|
any
|
returns Gregorian day from a serial day number date.time, where Jan 1, 1900 is day 1
|
gdow(SDAY)
|
any
|
returns Gregorian day of week from a serial day number date.time, where Jan 1, 1900 is day 1
|
ghour(SDAY)
|
any
|
returns Gregorian hour of day from a serial day number date.time, where Jan 1, 1900 is day 1
|
gleap(SDAY)
|
any
|
returns 1 if the year that corresponds to a serial day number date.time, where Jan 1, 1900 is day 1, is a leap year, else returns 0
|
gmillisec(SDAY)
|
any
|
returns Gregorian milli second from a serial day number date.time, where Jan 1, 1900 is day 1
|
gminute(SDAY)
|
any
|
returns Gregorian minute of hour from a serial day number date.time, where Jan 1, 1900 is day 1
|
gmonth(SDAY)
|
any
|
returns Gregorian month from a serial day number date.time, where Jan 1, 1900 is day 1
|
gsecond(SDAY)
|
any
|
returns Gregorian second of minute from a serial day number date.time, where Jan 1, 1900 is day 1
|
gyear(SDAY)
|
any
|
returns Gregorian year from a serial day number date.time, where Jan 1, 1900 is day 1
|
jdate(YEAR,MONTH,DAY)
|
any
|
returns a serial day number, starting with Jan 1, 1900 as day 1
|
jnow
|
none
|
returns the current time as a serial day number, starting with Jan 1, 1900 as day 1
|
jstart
|
none
|
returns the time of the start of the GAMS job as a serial day number, starting with Jan 1, 1900 as day 1
|
jtime(HOUR,MIN,SEC)
|
any
|
returns fraction of a day that corresponds to hour, minute and second
|
Example:
(mycalendar.gms)
todaydate = jstart;
now = jnow;
year = gyear(todaydate);
month = gmonth (todaydate);
day = gday (todaydate);
hour = ghour(todaydate);
minute = gminute(todaydate);
second = gsecond(todaydate);
dow = gdow (todaydate);
leap = gleap(todaydate);
display todaydate,now, year, month, day, hour, minute, second, dow, leap;
date = jdate(year,month,day);
time = jtime(hour,minute,second);
display date,time;
scalar plus200days;
todaydate = jstart+200;
year = gyear(todaydate);
month = gmonth (todaydate);
day = gday (todaydate);
display todaydate,year, month, day;
|