get the current date in following form: dd_mm_yyyy_hh_mm in matlab

You can use the date function to get the current date and time, and then use the datestr function to format it into the desired form:

main.m
current_date = datestr(now, 'dd_mm_yyyy_HH_MM');
disp(current_date);
69 chars
3 lines

The now function returns the current date and time as a serial date number, which datestr then formats into a string using the specified format. Note that I used HH instead of hh for the hours, as HH gives the hours in 24-hour format whereas hh gives the hours in 12-hour format.

This will output the current date and time in the format dd_mm_yyyy_HH_MM (with underscores as separators between the components), e.g. 17_08_2021_17_32.

related categories

gistlibby LogSnag