bash get date code example
Example 1: date linux format yyyymmdd
date=$(date '+%Y-%m-%d')
date=$(date '+%Y-%m-%d %H:%M:%S')
echo $(date '+%Y-%m-%d')
Example 2: datetime echo shell script
$(date '+%d/%m/%Y %H:%M:%S')
Example 3: bash get current date
$(date)
echo $(date)
Example 4: shell script current time
#!/bin/bash
now="$(date)"
printf "Current date and time %s\n" "$now"
now="$(date +'%d/%m/%Y')"
printf "Current date in dd/mm/yyyy format %s\n" "$now"
echo "Starting backup at $now, please wait..."
Example 5: echo date in bash
date +'FORMAT'
date +'%m/%d/%Y'
date +'%r'
backup_dir=$(date +'%m/%d/%Y')
echo "Backup dir for today: /nas04/backups/${backup_dir}"
Example 6: bash date
date