Hallo Team,
I have a simple request and i would appreciate your help.
I would like to use two dates in my script lets:
A=$(date +"%d %B %Y")
echo $A
23 June 2014
That's awesome now we cooking. Now i want B to be on the previous month
eg:
echo $B Should give me
23 May 2014
I would like to use these two arguments in my script below:
../getUsageDetailsFromMind_Where.pl "where accountid in (select id from accounts where parent = 77) and calldate between '20 MAY 2014' and '19 JUN 2014' and destination in (select distinct accountani from asani where (accountani between '0124264000' and '0124264611'))" MHG_Bitts_Only_Billing_201406 Y Y N;
../getUsageDetailsFromMind_Where.pl "where accountid in (select id from accounts where parent = 77) and calldate between '20 MAY 2014' and '19 JUN 2014' and destination in (select distinct accountani from asani where (accountani between '0116712000' and '0116712999'))" MHG_MedScheme_Only_Billing_201406_1 Y Y N;
My question is how do i set B as a variable to give me the desired output?
Regards,
What's your system? On Linux you can do things like
date -d "2014/01/01 - 1 month"
to get the last month.
If you don't, it may take thing like this to get handy date math.
Thank you Corona,
I am using Redhat Linux and your suggestion works but how do I initialize variable B?
Hi You can get like "23 5 2014" using below script
echo $(date +"%d") `expr $(date +"%m") - 1` $(date +"%Y")
..not able to print word "May" though..working on it
Ugh, that is not how you do it...
Have you read the link I linked? Have you read the example I showed you? They show you how.
Hallo Corona,
I saw the your link its awesome but its not giving me my format.
Makarand awesome feedfack only if i can get :
23052014 not 2352014
that would be great.
In what way does it "not work"? date supports your format:
$ date.pl +"%d %B %Y"
23 June 2014
$
What did you do? In what way did it "not work"?
Try getting the date in YYYY/MM/DD format, then using GNU date or the Perl script to convert it into the format you like in both -d "DDDD/MM/YY" and -d "DDDD/MM/YY - 1 month".
Hallo Corona,
[mind@util1-pkl REPORTS]$ date.pl +"%d %B %Y"
-bash: date.pl: command not found
[mind@util1-pkl REPORTS]$ date -d "2014/06/23 - 1 month"
Fri May 23 00:00:00 SAST 2014
[mind@util1-pkl REPORTS]$
There are 2 Options on my script which i can use:
Option A:
../getUsageDetailsFromMind_Where.pl "where accountid in (select id from accounts where parent = 77) and calldate between '20 MAY 2014' and '19 JUN 2014' and destination in (select distinct accountani from asani where (accountani between '0124264000' and '0124264611'))" MHG_Bitts_Only_Billing_201406 Y Y N;
../getUsageDetailsFromMind_Where.pl "where accountid in (select id from accounts where parent = 77) and calldate between '20 MAY 2014' and '19 JUN 2014' and destination in (select distinct accountani from asani where (accountani between '0116712000' and '0116712999'))" MHG_MedScheme_Only_Billing_201406_1 Y Y N;
Or Option B:
../getUsageDetailsFromMind_Where.pl "where accountid in (select id from accounts where parent = 77) and calldate >= to_date('20052014', 'ddmmyyyy') AND calldate <= to_date('19062014', 'ddmmyyyy')and destination in (select distinct accountani from asani where (accountani between '0124264000' and '0124264611'))" MHG_Bitts_Only_Billing_201406 Y Y N;
../getUsageDetailsFromMind_Where.pl "where accountid in (select id from accounts where parent = 77) and calldate >= to_date('20052014', 'ddmmyyyy') AND calldate <= to_date('19062014', 'ddmmyyyy') and destination in (select distinct accountani from asani where (accountani between '0116712000' and '0116712999'))" MHG_MedScheme_Only_Billing_201406_1 Y Y N;
This script has to be run every month on the 20th.
On Option A:
variableA='20 MAY 2014'
variableB='19 JUN 2014'
Or Option B:
VariableA='20052014'
VariableB='19062014'
First off, you don't need my date.pl because you have GNU date. It says in the thread that it's a minimal GNU date imitation, if you have GNU date you don't need it.
Second off, you clearly can't run date.pl if you didn't make the file.
Third off, you clearly can't run it just by typing in 'date.pl', but by typing in './date.pl' as my posts clearly illustrate.
Fourth off... You don't need my date.pl because you have GNU date.
Lastly: You haven't tried any of my or anyone else's suggestions at all, preferring to wait for a whole answer. I refuse to accept that you're that helpless, but:
DAY=$(date +%Y-%m-%d)
CURDAY=$(date -d "$DAY" +"%d %B %Y")
PREV=$(date -d "$DAY - 1 month" +"%d %B %Y")