Operating System - HP-UX
1833758 Members
2445 Online
110063 Solutions
New Discussion

the way make the date type

 
SOLVED
Go to solution
???_185
Regular Advisor

the way make the date type

I try to make date type like this 20051010
how can I make this by using date command.
2 REPLIES 2
Patrick Wallek
Honored Contributor
Solution

Re: the way make the date type


If this is in a script:

DATE=$(date +%Y%m%d)

See 'man date' for more details.
Hein van den Heuvel
Honored Contributor

Re: the way make the date type

You probably want a shell/date solution as Patrick nicel provided.

But just by chance I gave a perl solution with to a similar problem just seconds ago in: http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=964944

The isolated part solution:

$ perl -e '@t=localtime; printf("%04d%02d%02d\n",1900+@t[5],1+@t[4],@t[3])'

20051012


Maybe it will come in handy.
Btw... your example date makes it hard to see wether you want YYYYMMDD or YYYYDDMM.
Flip the last two printf arguments accordingly.

Hein