![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sed: zero-padding dates (or: convert d/m/yyyy to dd/mm/yyyy) | jgrogan | Shell Programming and Scripting | 3 | 07-30-2009 01:12 AM |
| Date difference between 2 dates in 'yyyy-mm-dd hh:mm:ss' format | muay_tb | Shell Programming and Scripting | 4 | 04-07-2009 02:16 PM |
| Format date from MM/DD/YYYY to YYYYMMDD | ChicagoBlues | UNIX for Dummies Questions & Answers | 5 | 03-24-2009 07:10 PM |
| Need script to generate all the dates in DDMMYY format between 2 dates | frozensmilz | Shell Programming and Scripting | 2 | 01-29-2009 06:06 AM |
| sed to display date in dd/mm/yyyy format | sars | Shell Programming and Scripting | 2 | 02-15-2007 03:32 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
fetch dates for last 36 days in format yyyy-mm-dd
can anyone please suggest me some ideas for writing a korn shell script which will go back to 36 days from current day and print each day (incremented by 1) in the format yyyy-mm-dd until the current day.
Thanks Mark |
|
|||||
|
There are a number of articles regarding date arithmetic on the site:
try Yesterdays Date/Date Arithmetic from the FAQs - you may find your answer (or something close) in there. What have you tried so far ? Post any code you may have and you're likely to get some good assistance. Cheers |
|
||||
|
fetch dates for last 36 days in format yyyy-mm-dd
This is the code i have so far. for now the loop is for 5 days. later i wish to update it to 36 days. Code:
#!/bin/ksh set -x i=1 while [ $i -le 5 ]; do _day=`date +%Y%m%d` newday=`expr $_day - $i` echo $newday echo "=================================" i=`expr $i + 1` echo $i done but i have a problem, expr 20091001 - 2 then i see this newday=20090999 Can anyone please suggest me. Thanks Mark Last edited by vgersh99; 10-01-2009 at 01:02 PM.. Reason: code tags, PLEASE! |
|
|||||
|
heres a simple way:- Code:
#!/bin/ksh set -x i=1 while [ $i -le 5 ]; do date -d "`date +%Y`-01-01 +$(( `date +"%j"` - $i ))days" +%Y-%m-%d i=`expr $i + 1` echo $i done i have used a simple trick to convet the current calender date into julian date, substract it by 1, and convert back it to the calendar date
|
|
||||
|
one another way, Code:
date --date="36 days ago" +"%Y-%m-%d" Use a variable and reduce the 36 upto required num, and proceed. As, I have no experience in writing korn shell script !!! Write the above suggested by your own. |
|
||||
|
the geek - Your method is good as long as the OP has GNU date installed on his machine. You can also try perl. Code:
#!/bin/ksh
# will run on Solaris with the date/time format %s problem.
end=$( perl -e ' print time;' )
start=$(( end - ( 86400 * 36) )) # 36 days in the past
while [[ $end -ge $start ]]
do
perl -e 'use POSIX qw(strftime);
$mt = strftime "%a %b %e %H:%M:%S %Y", localtime($ARGV[0]);
print $mt,"\n";' $start
start=$(( $start + 86400 ))
done
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|