LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

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

Rep: Reputation: 0
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
 
Old 10-21-2007, 01:26 AM   #2
reverse
Member
 
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Rep: Reputation: 30
Code:
       %A     locale’s full weekday name (e.g., Sunday)
 
Old 10-21-2007, 07:18 PM   #3
PAix
Member
 
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
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 07:21 PM.
 
Old 10-24-2007, 01:58 PM   #4
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 230Reputation: 230Reputation: 230
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'
1970 01 01 Thursday
 
Old 10-25-2007, 08:38 AM   #5
PAix
Member
 
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, 09:03 AM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 62
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, 09:18 AM   #7
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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, 09:20 AM   #8
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,362

Rep: Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910Reputation: 1910
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.
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 04:16 AM.

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