date format in shell script

Shell date format examples.

#!/bin/sh
date
date +"%Y%m%d" #YYYMMDD
date +"%Y-%m-%d" #YYY-MM-DD
date +"%Y-%m-%d %H:%M:%S %p" #YYY-MM-DD HH:MM:SS
date +"%Y-%m-%d %H:%M:%S %p %A" #YYY-MM-DD HH:MM:SS full weekday name
date +"%Y-%m-%d %H:%M:%S %p %A %Z" #YYY-MM-DD HH:MM:SS full weekday name timezone
date +"%a" #abbreviated weekday name, ex: Sun, Mon, Tue,...
date +"%A" #full weekday name
date +"%u" #numerical weekday number, 1-7, 1 Monday and 7 is Sunday
date +"%w" #numerical weekday number, 0-6, 0 is Sunday and 6 is Saturday
date +"%W" #nth week of the year from 00-53, with Monday as the first day of week
date +"%V" #nth week of the year from 00-53, with Sunday as the first day of week
date +"%b" #abbreviated month name, ex: Jan, Feb, Mar, ...
date +"%B" #full month name
date +"%y" #last 2 digits of the year
date +"%j" #nth day of the year, 001-366

output:

Sun Mar  1 14:35:49 EST 2015
20150301
2015-03-01
2015-03-01 14:35:49 PM
2015-03-01 14:35:49 PM Sunday
2015-03-01 14:35:49 PM Sunday EST
Sun
Sunday
7
0
08
09
Mar
March
15
060

Search within Codexpedia

Custom Search

Search the entire web

Custom Search