You can parse a date in a specific format in FreeBSD using:
date -j -f "$input_fmt" "$input_date" +"$output_fmt"
According to the date
manpage:
-j
Do not try to set the date. This allows you to use the
-f
flag in addition to the+
option to convert one date format to another. Note that any date or time components unspecified by the-f format
string take their values from the current time.-f input_fmt
Use
input_fmt
as the format string to parse thenew_date
provided rather than using the default[[[[[cc]yy]mm]dd]HH]MM[.SS]
format. Parsing is done usingstrptime(3)
.
More info about the format flags is in the strftime
manpage.
For example:
date -j -f "%d %b %Y" "18 Feb 2025" +"%Y-%m-%d"2025-02-18