![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Friendz.. plz help me on this date function. | psn123 | UNIX for Advanced & Expert Users | 14 | 07-23-2008 01:09 PM |
| Function to find day of any given date. | RRVARMA | Shell Programming and Scripting | 5 | 05-12-2008 12:19 AM |
| Date Function | charandevu | Shell Programming and Scripting | 1 | 04-02-2008 06:12 AM |
| Date Function | charandevu | Shell Programming and Scripting | 1 | 04-02-2008 04:44 AM |
| date function | abey | Shell Programming and Scripting | 2 | 02-27-2006 01:28 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
hi guys!
just want to ask if you could help me with the sript i'm working on. i need to automatically generate a summarized report everyday for all transactions the day before and ftp it to another machine. my only problem is that i need to name the file as the date yesterday. for example if i would generate a report today (09172001), the filename should be 09162001.txt, i've read the man for date but i haven't got a clue as to what to do. please help. thanks! Last edited by crpalermo; 09-16-2001 at 11:23 PM. |
| Forum Sponsor | ||
|
|
|
|||
|
Dear friend
write a few lines in the shell as follows: bye using date format command store today's date value in variable dt hence if todays date is 09282001 in mmddyyyy format dt='09282001' now store value of dt to a file echo $dt>file1 now cut value of today's date in variable v1 v1=`cut -c3-4 file1` now find out value of previous date by using expr command v2=`expr $v1 -1` now prepare the full date by replacing 3rd and 4th chr of file1 by value of v1 Of course you will also have to add validations for last date of months and for february also hope expr command will help you Wish you all the best yours friendly VRJoshi |
|
|||
|
just a thought. I dont see much use of processing data and labeling it the day befor. why not just run it from cron @ end of bussiness day or even at 11:55pm then u dont have to worry about adding and subtracting from the date.?
also if you look at the date man page at the bottom there are plenty of examples of getting the date in a format you would like. |
|
|||
|
ptx: i agree but that is why i said run it late.ie 11:56. most business should be done.
but w/ your example i completly agree and it is a great idea to get the date string first then sleep for 2 mins then finish. |
|
||||
|
Well, I'm bored this afternoon...so
Code:
#!/usr/bin/ksh
set -A months 0 31 28 31 30 31 30 31 31 30 31 30 31
typeset -Z2 month_y day_y
today=$(date +%m%d%Y)
month_t=${today%??????}
year_t=${today#????}
day_t=${today%????}
day_t=${day_t#??}
((year_t % 100)) && ((leap = !(year_t % 4))) || ((leap = !(year_t % 400)))
((leap)) && ((months[2] = months[2] + 1))
((year_y = year_t))
((month_y = month_t))
((day_y = day_t - 1))
if ((!day_y)) ; then
((month_y = month_y - 1))
if ((!month_y)) ; then
((year_y = year_y-1))
((month_y = 12))
fi
((day_y = months[month_y]))
fi
yesterday=${month_y}${day_y}${year_y}
echo yesterday = $yesterday
exit 0
|
| Tags |
| linux |
| Thread Tools | |
| Display Modes | |
|
|