You can try:
#!/bin/bash
d=$(date +%Y-%m-%d)
echo "$d"
EDIT: Changed y to Y for 4 digit date as per QuantumFool's comment.
You can also use the shorter format
From the man page:
%F full date; same as %Y-%m-%d
Example:
#!/bin/bash
date_today=$(date +%F)
date_dir=$(date +%F -d yesterday)
simple:
today="$(date '+%Y-%m-%d')"
yesterday="$(date -d yesterday '+%Y-%m-%d')"
you should man date
first
date +%Y-%m-%d
date +%Y-%m-%d -d yesterday
Source: Stackoverflow.com