date time

Home date time

How to format dates in shell scripts

When using dates in a shell script, you can format them like this: $(date +[format]) Here are some examples: $(date +”%Y%m%d)20080508 ——————– $(date +”%Y-%m-%d)2008-05-08 ——————– $(date +%D) which is shorthand equivalent for $(date +”%m/%d/%Y) 05/08/2008 To include time: $(date +%r)

How to view the current time from the command line

To see the current time from the Ubuntu or Linux command line: date which will give you: Fri May 30 15:53:21 EDT 2008 To see how to include and format dates and times in your shell scripts, see this post:

How to Format Dates in Shell Scripts – 2020 Guide

When using dates in a shell script, you can format them like this: $(date +[format]) Here are some examples: $(date +”%Y%m%d)20080508 ——————– $(date +”%Y-%m-%d)2008-05-08 ——————– $(date +%D) which is shorthand equivalent for $(date +”%m/%d/%Y) 05/08/2008 To include time: $(date +%r)