Help to generate date from day of the year


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help to generate date from day of the year
# 1  
Old 06-04-2010
Question 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 could get any information for converting day of the year to date.

Could anyone please help me in this

Thanks in advance....
# 2  
Old 06-04-2010
With gnu date,

Code:
-bash-3.1$ str=2005029
-bash-3.1$ yr=$(echo $str | cut -c3-4)
-bash-3.1$ dd=$(echo $str | cut -c6-7)
-bash-3.1$ echo $yr   
05
-bash-3.1$ echo $dd
29
-bash-3.1$ date -d "01/01/${yr} +${dd} days -1 day"
Sat Jan 29 00:00:00 CET 2005
-bash-3.1$

# 3  
Old 06-04-2010
MySQL

Thanks alot ... Smilie
It was a great help Smilie
# 4  
Old 06-04-2010
Quote:
Originally Posted by anchal_khare
Code:
-bash-3.1$ str=2005029
-bash-3.1$ yr=$(echo $str | cut -c3-4)
-bash-3.1$ dd=$(echo $str | cut -c6-7)


There's no need for an external command (cut):
Code:
str=2005329
yr=${str%???}
dd=${str#????}

Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Julian day to dates in YEAR-MONTH-DAY

hello, I have many files called day001, day002, day003 and I want to rename them by day20070101, day20070102, etc. I need to do it for several years and leap years as well. What is the best way to do it ? Thank you. (1 Reply)
Discussion started by: Ggg
1 Replies

2. UNIX for Dummies Questions & Answers

Sort file by day of year

Hello, It's a shame to not be able to do what I need, but I am sure you will : Here is what I have in my log file : New File: 95106 Jun 6 48 TAG__KSO__2012092_0.TAB New File: 95106 Mar 26 48 TAG__KSM__2012020_0.TAB New File: 95106 Mar 26 48 TAG__KSO__2012020_0.TAB New File: 95106 May... (3 Replies)
Discussion started by: Aswex
3 Replies

3. Shell Programming and Scripting

Day of year to dd.mm.yyyy format

Hi, How can I convert day of year value in format(yy,doy) to normal formatted (dd.mm.yyyy) string also all of them with awk or awk system function? in_file.txt --------- 12,043 12,044 12,045 12,046 out_file.txt ---------- 12.02.2012 13.02.2012 14.02.2012 15.02.2012 imagine... (5 Replies)
Discussion started by: kocaturk
5 Replies

4. 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

5. Shell Programming and Scripting

Get day of year

Hi, I wold like to know the day of year from a date in input. I know to get this from sysate with date +%j But from a date in input? :confused: Thanks (2 Replies)
Discussion started by: pinguc
2 Replies

6. Shell Programming and Scripting

Get yesterday's date in year-month-day format?

Dear All, Actually, i'm doing some reporting job and i need to pass yesterday's date in Year-Month-Day format(e.g. 2009-06-10) to another program for generating 2009-06-10 report. to get today's date, it's easy to just date '+%Y%m%d' , but no idea how can i get this kind of format for... (2 Replies)
Discussion started by: tiger2000
2 Replies
Login or Register to Ask a Question