Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This 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.


  Search this Thread
Old 10-20-2007, 08:47 PM   #1
LQ Newbie
Registered: Jun 2007
Posts: 17

Rep: Reputation: 0
date command is not accepting


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 there any possible to use date command?

Old 10-21-2007, 02:26 AM   #2
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Rep: Reputation: 30
       %A     locale’s full weekday name (e.g., Sunday)
Old 10-21-2007, 08:18 PM   #3
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
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
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!

Last edited by PAix; 10-21-2007 at 08:21 PM.
Old 10-24-2007, 02:58 PM   #4
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
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:
$ date -d "19700101" +'%Y %m %d %A'
1970 01 01 Thursday
Old 10-25-2007, 09:38 AM   #5
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
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
Old 10-25-2007, 10:03 AM   #6
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
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.
Old 10-25-2007, 10:18 AM   #7
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
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.
Old 10-25-2007, 10:20 AM   #8
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
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
> date -d "13-Dec-1901 21:45:52" +%s
> date -d date -d "19-Jan-2038 04:14:07" +%s
Instead, on a 64-bit machine you can easily span from year 0001 to 9999 since the integer representation is beyond these limits.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
'date' command format Neorio Linux - General 3 01-18-2011 06:18 AM
command for date DarReNz Solaris / OpenSolaris 7 09-05-2006 10:53 AM
date command aetucker1 Linux - General 3 01-21-2005 01:57 PM
date command question lifetaster Programming 4 02-23-2004 08:05 PM
help with Date command in script icw_sec Programming 6 01-06-2004 12:02 PM

All times are GMT -5. The time now is 02:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration