Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
The Unix/Linux date command will accept no date before 01 Jan 1970 or after 2038.
So the date command is not appropriate for your purpose. There are other ways - i'm sure that someone will advise you appropriately.
put in a file called myfile 19700101 and run this code
Code:
echo $(date -f myfile)
Change the date to before 1970 to check what I say. then try after 2038 (not sure what month day)
Good luck.
I think Reverse's previous comment was pointing out that you were probably looking for a format +%Y%m%d YYYYMMDD, but instead of the day you put %A which is the weekday. I only explain that because it took me more than a few moments. Sorry Reverse, I'm a bit slow tonight!
A nicely spaced date format is not to be sniffed at and is exceedingly useful in human terms, but often a compacted YYYYMMDD is a very convenient sortable date for use in logs to simplify further searching, sorting and processing; a personal preference and possibly the reason for Monu's original choice of format. Notwithstanding that, a very useful pointer Archtoad6 that introduces a bit of readability.
I think Monu's greater problem is in using a date before 01 January 1970. I believe that there is a Perl Date-Calc module (unsure of the capitalisation) that will handle the significantly greater range which is of interest. No reason why that should get in the way of useful information though.
YYYYMMDD format is the best. Sort a list of these dates in dictionary order, and you get chronological sort order for FREE!
The command line date command only works for dates between ~1902 and ~2038. If you want to do a lot of date manipulation, you're better off using a proper date processing library and using a more sophisticated language than shellscript. As PAix mentioned, the Date::Calc module with Perl is very usable. IIRC it handles dates in the conventional western calendar back to 1 A.D.
Remember that different countries changed their calenders at different times in history. The US didn't adopt the Gregorian calendar until 1752, Alaska in 1867. Greece did in 1923.
Indeed, the range of dates we can span with the date command depends on the machine architecture, 32 or 64-bit. On a 32-bit machine the maximum representable signed integer is (2^32 -1)/2 that is plus or minus 2147483648. Since the date command uses seconds since epoch to do calculations and the epoch is 01-Jan-1970 01:00, the range of dates on a 32-bit machine is
Code:
> date -d "13-Dec-1901 21:45:52" +%s
-2147483648
>
> date -d date -d "19-Jan-2038 04:14:07" +%s
2147483647
Instead, on a 64-bit machine you can easily span from year 0001 to 9999 since the integer representation is beyond these limits.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.