Derive the Year value from the date value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Derive the Year value from the date value
# 1  
Old 10-11-2011
Derive the Year value from the date value

Hi All,

I have two dates: PREVIOUS_DAY and CURRENT_DAY. I need to test the these two values years are same or not.

PREVIOUS_DAY like '%y%m%d' i.e values like 111010, 111011, 111012 etc.

For CURRENT_YEAR:'date +%Y' use this command.
How can derive the year value from PREVIOUS_DAY and o/p value like '+%Y' i.e 2010, 2011 etc.

I am trying PRVIOUS_DAY_YEAR:eval $PREVIOUS_DAY '+%Y' but its not working. Please help me in this regard.

Thanking in advance ........

Regards,
Dathu
# 2  
Old 10-11-2011
The following will help you understand:
Code:
#!/usr/bin/ksh
while true; do
  echo "Enter yymmdd:"
  read mPrev
  if [[ ${mPrev} -le 120101 ]]; then
    echo "Century 21"
    mPrev='20'${mPrev}
  else
    echo "Century 20"
    mPrev='19'${mPrev}
  fi
  echo "mPrev <${mPrev}>"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Derive date and its Volume number

Hi All, I have a list of date number (YYYYMMDD) and its own number in a file. Here is the example 20170320 D100001 D100002 D100003 20170321 D200001 D200002 D200004 D200005 20170322 D200005 D200006 D200007 (4 Replies)
Discussion started by: ckwan123
4 Replies

2. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies

3. Shell Programming and Scripting

Find week of the year for given date using date command inside awk

Hi all, Need an urgent help on the below scenario. script: awk -F"," 'BEGIN { #some variable assignment} { #some calculation and put values in array} END { year=#getting it from array and assume this will be 2014 month=#getting it from array and this will be 05 date=#... (7 Replies)
Discussion started by: vijaidhas
7 Replies

4. Shell Programming and Scripting

How to list files that are not first two files date & last file date for every month-year?

Hi All, I need to find all files other than first two files dates & last file date for month and month/year wise list. lets say there are following files in directory Mar 19 2012 c.txt Mar 19 2012 cc.txt Mar 21 2012 d.txt Mar 22 2012 f.txt Mar 24 2012 h.txt Mar 25 2012 w.txt Feb 12... (2 Replies)
Discussion started by: Makarand Dodmis
2 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Previous Year Date

Hi Gurus, I would like to get the date for the previous year based on the date I specify. For e.g. If I input today's date (i.e. 20130422) I need to get 20120422. We don't have GNU and use K Shell. Any help is highly appreciated. Thanks Shash (4 Replies)
Discussion started by: shash
4 Replies

6. Shell Programming and Scripting

How to derive the last Sunday's date when Current date value is passed

Hi All, I have a requirement in my project where a batch runs on any day of a week. The input files will land to the server every Sunday. I need to read these files based on the current BUS_DAY (which falls any day of the week). For e.g : if the BUS_DAY is 20120308, we need to derive the... (3 Replies)
Discussion started by: dsfreddie
3 Replies

7. Shell Programming and Scripting

get date for all saturdays in given year

Hello Guys I browsed through site for mentioned requirement all solutions I got in perl I am looking for something in unix script for same any suggestions thanks (1 Reply)
Discussion started by: joshiamit
1 Replies

8. Shell Programming and Scripting

Awk convert from day of year to date

Hello everyone, I have a file which has day of year in one of the columns (JD=substr($0,72,3)). The bellow scripts shows me the minimum and maximum values of the JD and I would like to convert the JD to date. #!/bin/gawk -f { check=substr($0,1,1) if (check == "S") { ... (6 Replies)
Discussion started by: alex2005
6 Replies

9. Shell Programming and Scripting

Help to generate date from day of the year

Hi I want to convert the day of the year(yyyyddd) to date in mmddyy format Example: input is 2005029 --------> 29th day of 2005 I have to get the output as 01292005 ---> jan 29th 2005 I've to do this in K-Shell There were threads that dealt with coverting date to day of the year but I... (3 Replies)
Discussion started by: sudhamayeev
3 Replies

10. Shell Programming and Scripting

Derive date from a calendar

I'm using AutoSys as scheduler for my application. I maintain a calendar in AutoSys which specifies when a job should run. A unix shell scripts runs on the days spceified by calendar and processes incoming files. These incoming files contain dates embedded in the filenames. My job needs to... (2 Replies)
Discussion started by: autouser123
2 Replies
Login or Register to Ask a Question