Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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'

Returns:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:

2023-02-06"%20"11:13:59

>Solution :

The conversion specifier %% expands to a literal %

$ date +%%
%

so

$ date '+%Y-%m-%d%%20%H:%M:%S'
2023-02-06%2011:20:17

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading