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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple date query in ksh

Status
Not open for further replies.

Sambo8

Programmer
May 10, 2005
78
NZ
Hi There,

I'm very new to ksh I have a script that goes into a folder that begins with a date and creates a file as follows:

#!/usr/bin/ksh
cd /work/sam/$(date +%Y%m%d)
touch hello.txt

this works to create a file called hello.txt in the path /work/sam/20080508/

now I want that to be minus 3 days? I've tried -3 and - %d3 with no joy - please can anyone help?

Cheers,
Sam
 
Hi

If you have GNU [tt]date[/tt], use the -d ( --date=DATE ) switch :
Code:
date -d '-3 days' +%Y%m%d

[gray]# or[/gray]

date -d '3 days ago' +%Y%m%d
Otherwise see faq822-4802.

Feherke.
 
If you don't have the GNU date then there's a really good date function written by PHV at faq80-4800

On the internet no one knows you're a dog

Columb Healy
 
Because I didn't read to the end of your post :~/ My bad!

On the internet no one knows you're a dog

Columb Healy
 
PHV put that FAQ in both the "UNIX scripting" and the "-General UNIX discussion" forum. So it is basically the same info in two separate locations.


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top