Is there a way to retrieve the current date and time at execution time? I would like to write it to an individual output file in a loop at execution time, however, I can only find system.date and system.Time which do not change over time.
The jnow functions returns the current time as serial number. An overview about the time and calendar functions in GAMS can be found here. And here you can find an example how they can be used.
thank you very much for the quick answer! That seems to be exactly what I need. However, I’m having trouble writing this to a file in a meaningful way. When I try this:
There is a way, but none that is available as direct function. One basically has to program this, since GAMS allows for white padding at the beginning of a number in put statements (e.g. put m:2:0; to have a width of 2 for the scalar m), but not for zero padding. Here is a solution using a macro:
File fout / 'formatted_time.txt' /;
Scalar current_hour, current_minute, current_second;
current_hour = ghour(jnow);
current_minute = gminute(jnow);
current_second = gsecond(jnow);
* Check if < 10 for each element and print '0' if not
$macro formattedTime(h,m,s) if(h < 10, Put '0';); Put h:0:0, ':'; if(m < 10, Put '0';); Put m:0:0, ':'; if (s < 10, Put '0';); Put s:0:0;
Put fout;
Put / 'The current time is: ';
formattedTime(current_hour,current_minute,current_second)
PutClose;