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!
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
From the man page:
date - print or set the system date and time
I don't think it does what you want ie check random strings for validate dates (if that's what you meant).
The GNU date command accept the -d option to specify a date other than the current date. From the info page:
Quote:
`-d DATESTR'
`--date=DATESTR'
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
input formats::.
Check the section "Note Date input formats" for details on how to specify the past date. The following are all working examples:
Code:
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.