How to put values like today() into a string?

For example, if I have a variable like this:

A = "Dog";
B = "Cat";

I can do this:
C = "I have both $A and $b";

How do I do something like the below and add today’s value, e.g., October 10, 2021?
D = “I walked my $A and $B on $today()”.

Thanks.

Just add ():
D = "I walked my $A and $B on $(today())"

NB: using Dates

1 Like
julia> "If you want to confuse people, you can interpolate longer expressions: $(begin;a=3;b=a^2;b-1;end)"
"If you want to confuse people, you can interpolate longer expressions: 8"

Don’t do this, but the fact that you can is pretty cool.

1 Like

And begin; end; could be replaced by ():
$((a=3;b=a^2;b-1))

2 Likes

And

Dates.format(today(), "U d, YYYY")
"October 10, 2021"

does the formatting, returning a String.

3 Likes

Many thanks for all the replies. I learned many pieces of important knowledge about Julia.

2 Likes