Add %20 as part of date format in shell

I am trying to add %20 between the date and time, to return YYY-MM-DD%20HH-MM-SS

How can I escape the % symbol?

date '+%Y-%m-%d%20%H:%M:%S'


2023-02-06                   %H:12:40

And when I quote the %20:

date '+%Y-%m-%d\"%20\"%H:%M:%S'

The quotes are also returned:


>Solution :

The conversion specifier %% expands to a literal %

$ date +%%


$ date '+%Y-%m-%d%%20%H:%M:%S'

However, as this implies you are using the string in a URL, I would recommend simply outputting a space, and letting whatever is constructing the URL ensure that necessary characters are escaped.

Leave a Reply