Month Substitution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Month Substitution
# 1  
Old 06-01-2010
Month Substitution

Team,

How do i fetch details of the last day of the month i.e 31st,30th

because we receive daily status report but not for the last days of the month..

because when i do an
Code:
echo `date +%Y%m `${yesterday}

it retrieves me 20100631 where as it should have been 20100531..

Hmm interesting!

PS:Please dont treat this as an assignment

Warm regards
Whizkidash

Last edited by Yogesh Sawant; 06-01-2010 at 10:00 AM.. Reason: added code tags
# 2  
Old 06-01-2010
have you seen this ?
# 3  
Old 06-01-2010
No...

But i have found solution for the same

If i do this..
Code:
echo `TZ=TZ+24 date +%Y%m%d`

It works

Thanks mate!

Cheers
Whizkidash

Last edited by Yogesh Sawant; 06-07-2010 at 02:20 AM.. Reason: added code tags
# 4  
Old 06-01-2010
I think your code works only for a few hours of the day.
# 5  
Old 06-01-2010
I agree. Manipulating the TZ variable in this manner can only work properly 24/7 in the GMT timezone.

The original command posted does not work because ${yesterday} is not set and evaluates to blank. The command as posted just executes:
Code:
date +%Y%m

If only we knew which Operating System and Shell the O/P has?

Iin general it is usually better to use a 00:01 cron to create a reference file "today" and age the file daily to create "yesterday" and "day-before-yesterday" files. Each file can contain the date in the format required by the reporting process or the reporting process could use the timestamp of the relevant file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Get last month files

Hi All, How to get last month files. Ex : 1st Jan i have to get Dec 31 days files and on Feb 1st i have to get Jan 31 days files and on Mar 1st i have to get Feb 28 days files. Below are the example files with date and timestamp. aaa.txt.timestamp aaa.txt.timestamp aaa.txt.timestamp Please... (7 Replies)
Discussion started by: kiranparsha
7 Replies

2. Shell Programming and Scripting

Need last month files after 10th of every month

Hi, I need all file names in a folder which has date >= 10th of last month, Example : files in folder AUTO_F1_20140610.TXT BUTO_F1_20140616.TXT CUTO_F1_20140603.TXT FA_AUTO_06012014.TXT LA_AUTO_06112014.TXT MA_AUTO_06212014.TXT ZA_AUTO_06232014.TXT Output: AUTO_F1_20140610.TXT... (9 Replies)
Discussion started by: nani1984
9 Replies

3. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

4. Shell Programming and Scripting

Convert From Month Number to Month Name

Hi, I have a script that accepts an input date from the user in yyyy-mm-dd format. I need to get the mm-dd part and convert it to month name. example: 2011-11-15 I want that to become "Nov 15" I don't have the GNU date, I am using an AIX os. Thanks. (1 Reply)
Discussion started by: erin00
1 Replies

5. Shell Programming and Scripting

How to get first sunday of the month?

Hi, Please can someone help me in getting first sunday date of a month. i_year=`date +%Y` ny_first_sun_nov=`cal 10 $i_year | sed '/^$/d' |head -3 |tail -1| rev | cut -c1` This works good if the first sunday has a value but not if it is blank and first sunday falls on second week. ... (17 Replies)
Discussion started by: infyanurag
17 Replies

6. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

7. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

8. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies

9. Shell Programming and Scripting

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies

10. Shell Programming and Scripting

Month name

Hi, Could you pls help me out in finding the name of next month.? For eg: date +"%b" gives the current month ie 'Jul' I want to get the output as 'Aug' Thanks, Jerry (4 Replies)
Discussion started by: jerrynimrod
4 Replies
Login or Register to Ask a Question