awk variable into shell command "date -d": possible...?

Hello, there!
I am trying to pass an awk variable into a shell command ['date'] in order to collect the result into an awk variable; in Bash it does work, as in:

v='2'; date -d "now + $v weeks"

But in awk it does not, as in:

v="2"
"date -d 'now + v weeks'" | getline newdate
close ("date -d 'now + v weeks'")
print newdate

Does anyone have any ideas as to why that is so and/or whether it can be done as I need it?
Thank you all, in advance.

v=2
awk -v newdate="$(date -d 'now + $v weeks')" '{print newdate}' myFile
1 Like

Or, to show how it can be done within awk itself:

awk 'BEGIN{v=2; cmd="date -d \"now + " v " weeks\""; cmd | getline newdate; close(cmd); print newdate}' 

The way of quoting is different than in shell..

Or if you put it in a file file.awk:

BEGIN {
  v=2
  cmd="date -d 'now + " v " weeks'"
  cmd | getline newdate
  close(cmd)
  print newdate
}
awk -f file.awk

That's exactly what I was looking for.
Thanks a bunch!