Avatar of fcarleton
fcarleton asked on

UNIX ksh parse year from date

How to parse year fron date
Shell Scripting

Avatar of undefined
Last Comment

8/22/2022 - Mon

date +%Y

I need to expound more on the question.  How can I get year in YYYY format from date. A table of date formatting codes would be real helpful.  Patterned after Mikes reply: date +%Y.  That yeilds the YY segment of the full CCYY year value.
echo `date +%Y`
prints 10


Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

By the way, there's no need to:
    echo `date +%Y`
    date +%Y
automatically prints to stdout.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

How about this:

  DateToParse="January 12, 1967"      # put whatever date you want here, in almost any format
  YEAR=`date -d "$DateToParse" +'%Y'`
  echo "The year is $YEAR"

Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.