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
woolmilkporc
Avatar of mikepflu
mikepflu
Flag of United States of America image

date +%Y
Avatar of fcarleton
fcarleton

ASKER

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

Fc
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of tel2
tel2
Flag of New Zealand image

By the way, there's no need to:
    echo `date +%Y`
because
    date +%Y
automatically prints to stdout.
Avatar of TRW-Consulting
TRW-Consulting
Flag of United States of America image

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"

ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Shell Scripting
Shell Scripting

The term 'shell' refers to a general class of text-based command interpreters most often associated with the UNIX and Linux operating systems. Popular shells include Bourne, Debian Almquist (dash), Korn (ksh), Bourne Again (bash) and the C shell family (csh). Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin on Windows and emulate a full Unix environment with complete shell capabilities. Terminal emulators, such as xterm, GNOME Terminal and OS X Terminal, can be used to access shell.

11K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo