date command is not accepting
Hi,
date command is not accepting year 0001 for example: date -d "00010101" +%Y%m%A error invalid date.. but when i use cal command it doesn't show me any errors. I want to use date command not cal command.is there any possible to use date command? thanks |
Code:
%A locale’s full weekday name (e.g., Sunday) |
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) 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! |
While +%Y%m%A will work, +"%Y %m %d %A" or +'%Y %m %d %A' is better practice -- it allows putting spaces in your format string:
Code:
$ date -d "19700101" +'%Y %m %d %A' |
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. Thanks PAix |
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 |
All times are GMT -5. The time now is 02:08 AM. |