Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a date to the 4th of the month

Status
Not open for further replies.

maxcrook

Programmer
Jan 25, 2001
210
GB
I have a script that needs to run from Crontab on the 1st of the month.

The script needs to change the date in the format 01-MMM-01
to the 04-MMM-01 each month.

How can I set the script up to do this ?

At the moment I have to manually go into the script and change the dates manually. I need the script to look at the current date ie (01-MMM-01) and change it to the 4th.

Does this make any sense ?
 
Ok - You need a script that will change the date to the 4th, and you want it to run on the 1st of each month.

Technically this is not difficult - set up a crontab entry that calls a script that sets the date.

However --- Are you sure that this is what you want to do? Changing the date is always a bit fraught, esp when you change it *backwards* which I'm assuming you'll want to do when your script has finished. Some files will have dates apparently in the future, things will behave strangely... If you have an Oracle database or two you will have problems with these. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
I'm a little confused as to what you want to do. Do you:

a) Wish to alter the system date to the fourth, as Mike implies and bearing in mind the possible difficulties that might entail; or

b) Simply change a reference date in a script so that every reference to 01 MMM yy becomes 04 MMM yy?

Can you clarify, please? Thanks.
 
I think we are all confused, but if you simply want to change a date string in a file then a simple sed may be the answer.
e.g you have a file called 'date' containing the string 01NOV2001
then if you use
sed s/01/04/1 date
this will substitute 01 with 04.
The /1 flag means the first occurence - you may need to change this of 01 appears multiple times in your file.
 
Sorry I knew it would be a little confusing !
I have an oracle database with accounts set to bill on 01-MMM-01. I need a script that will change all of these accounts to the 04-MMM-01 on the 1st of each month.

I need a script that will do this regardless of the date.
It is easy to do the sql to state update next_bill_date=04-NOV-01 where next_bill_date=01-NOV-01 however as i want this to run automatically I need the script to call the date from elsewhere without having to change it monthly.

I hope this makes sense ????/
 
Hi Max,

Ok - well there's no need to change the system date then - and Oracle will have a fit if you try it...

What about something like this?
[tt]
NEW_DATE=$(date '+%b-%y')
OLD_DATE="01-$NEW_DATE"
NEW_DATE="04-$NEW_DATE"

print "

Update TABLE_NAME Set
[tab]NEXT_BILL_DATE=$NEW_DATE
Where NEXT_BILL_DATE=$OLD_DATE;
Commit;

" > script.sql

#sqlplus user/password@your_db @script.sql
[/tt]

(You'll notice that I've commented out the call to sqlplus that will actually run the sql update statement.)

My Oracle skills are rubbish now, I can't remember whether or not you need single quotes around date constants...

If you do need the single quotes, two lines of the SQL statement must be changed to read:

[tab]NEXT_BILL_DATE='$NEW_DATE'
Where NEXT_BILL_DATE='$OLD_DATE';
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top