Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I am having problem with creatng date formate: YYYYMMDD .
My code is: date +%Y%m%d but its not working it. I checked %Y only displays current year not past year. suppose if i enter my date: 18240804 it doesn't accept it. IT only takes 20070804.. not past years. What is date -s do?
So my point is %Y is only for current year not for past year. I want to create script which accepts past years day and months like this: YYYMMDD. I read man page i couldn't find out what is date -s ? please provide me some example and with past year.
The GNU date command accept the -d option to specify a date other than the current date. From the info page:
Display the date and time specified in DATESTR instead of the
current date and time. DATESTR can be in almost any common
format. It can contain month names, time zones, `am' and `pm',
`yesterday', etc. For example, `--date="2004-02-27
14:19:13.489392193 +0530"' specifies the instant of time that is
489,392,193 nanoseconds after February 27, 2004 at 2:19:13 PM in a
time zone that is 5 hours and 30 minutes east of UTC. *Note Date
Check the section "Note Date input formats" for details on how to specify the past date. The following are all working examples:
date -d "23 June 1867" +%Y%m%d
date -d "Jul 11, 1968 - 3 days" +%Y%m%d
date -d "2 days ago" +%Y%m%d