Get date and time of several images in a single table

Hello everyone

I was trying to reuse the get time and date sample macro and is working just fine but I would like to use it with several images and, instead of showing a message window with the time and date, I would like to have those values in a table. Can be that possible? Sorry for such basic question, I am totally new at programming.

Thanks in advance for any reply,


// This macro demonstrates how to use the getDateAndTime() 
// function, available in ImageJ 1.34n or later.

  macro "Get Time" {
     MonthNames = newArray("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
     DayNames = newArray("Sun", "Mon","Tue","Wed","Thu","Fri","Sat");
     getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
     TimeString ="Date: "+DayNames[dayOfWeek]+" ";
     if (dayOfMonth<10) {TimeString = TimeString+"0";}
     TimeString = TimeString+dayOfMonth+"-"+MonthNames[month]+"-"+year+"\nTime: ";
     if (hour<10) {TimeString = TimeString+"0";}
     TimeString = TimeString+hour+":";
     if (minute<10) {TimeString = TimeString+"0";}
     TimeString = TimeString+minute+":";
     if (second<10) {TimeString = TimeString+"0";}
     TimeString = TimeString+second;


I’m not sure about what you want to do. The function getDateAndTime returns the current time (the clock of your system), and doesn’t even look at any image.

If you want to look at the last modification of an image, then you will need File.dateLastModified, if it’s something else, you might need to call non macro commands (through run or exec), that can depend on your operating system.

But, to answer to your question anyway, first, take a look at the introduction to macro programming from the wiki, there you will also find a link to the complete list of macro functions. The function setResult enables you to write to the Results table. If you don’t want to write to the Results table, but to create a separate window, it is also possible to use the print command, take a look at the SineCosineTable2 example.

Also, if you want to call your macro for various files in a directory, you might want to take a look at the “Process Folder” template.