It's easy to accept a date in a specified but non-standard format (date -j -f "EXISTING_DATE_FORMAT" "EXISTING_DATE" "OUTPUT_FORMAT"), and easy to adjust a date with the same command (date -j -v+1y "OUTPUT_FORMAT").

I have a date/time in a text string, that I need to convert (so date can understand it) and then adjust, before echoing it in a given format.

Unfortunately date -j -v+1y -f "EXISTING_DATE_FORMAT" "EXISTING_DATE" "OUTPUT_FORMAT" doesn't seem to be permitted, or at least isn't working for me. How can I get this effect?

  • Use a second date command inside $(command substitution) to convert from the existing format – Philippos Oct 9 '17 at 12:54
  • Can you enter this as an answer (hopefully with a simple example to show the exact syntax)? Then I can mark it as correct. – Stilez Oct 9 '17 at 13:12
  • Sorry, I only commented, because I don't have a FreeBSD machine to verify. – Philippos Oct 9 '17 at 13:56
  • Take the last example in the FreeBSD manual page for date as a further guide, and you can answer your own question. (-: – JdeBP Oct 9 '17 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.