Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
04-19-2009, 06:09 PM
|
#1
|
Member
Registered: Sep 2006
Distribution: MX-16 Modified using TDE
Posts: 239
Rep:
|
Absolute date
Hi,
I'm using Slackware 12.2, but I don't think this is a distro-specific question.
Is there a way I can display a date as an absolute date either by using bash or some other utility/app in Linux?
For example...
Convert month/day/year to 56778
Thanks,
-Joe
Edit...
Btw, I've already tried with the manpages for date and I don't seem to be able to find anything there to convert to absolute date. I've also crossposted to the OpenOffice Forum about this. This is for an assignment that is due Tuesday and of course, the textbook is written with MS Office in mind.
Last edited by joegumbo; 04-19-2009 at 06:22 PM.
Reason: typo
|
|
|
04-19-2009, 06:35 PM
|
#2
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
[QUOTE=joegumbo;3514453
Convert month/day/year to 56778
[/QUOTE]
WHAT IS an absolute date?
The example you give doesn't ring a bell, what is the mapping function you use? Number of days since ... ? As far as I can see it is not the number of seconds since 1970-01-01.
I can't imagine it is something date cannot do, but I admit, date's man page is not the best one to describe all the options.
Since you are referring to OpenOffice, is this something which can be done in Bash, or is it something you need in Calc?
jlinkels
|
|
|
04-19-2009, 06:48 PM
|
#3
|
Moderator
Registered: Aug 2002
Posts: 26,743
|
Per the LQ Rules, please do not post homework assignments. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.
That said and I find the subject of time very interesting but what do you mean by absolute date and how does this pertain to MS Office?
|
|
|
04-19-2009, 07:12 PM
|
#4
|
Member
Registered: Sep 2006
Distribution: MX-16 Modified using TDE
Posts: 239
Original Poster
Rep:
|
The question is not what you imagine it to be. I'm to convert a specific date to an absolute date. I'm not posting that date. I'm asking how to do this with non-MS software because I don't have MS Office installed. The textbook is explicit in how to do it with MS Excel.
I know how to do this in Excel...
In Excel, enter the date into a cell. Format > Cells... Format Cells > Number Tab > Number. It is then converted to an Absolute Date. If I had MS Office installed, I'd be done.
Do you consider it cheating to ask about other methods using FOSS? If I had wanted to cheat, I wouldn't have posted that this is an assignment and no one would be the wiser.
Absolute Dates are used to do such things as calculate how many days are between two dates by converting them to numbers without regard as to how many days are in each month, leap years, etc. and then doing calculations. For instance, how masny days between 2 dates centuries apart?
I'm not asking anyone to do the assignment; I'm asking for a non-MS procedure to follow to do the conversion.
Edit...
Never mind....
I figured it out on my own.
In Calc,
Enter a date into a cell. 11/22/2299 , e.g.
Format
Cells...
Make sure the "Numbers" tab is clicked
and under Format, click on -1234
Under Category, Change from Date by clicking on Number.
The date will be converted to a number that can be used for calculations. 146059 , e.g.
11/22/2299 = day number 146059
Lets say you wanted to know how many days there are between today's date and 4/19/1000. Just convert and find the difference. 
Last edited by joegumbo; 04-19-2009 at 08:04 PM.
|
|
|
04-19-2009, 08:09 PM
|
#5
|
Moderator
Registered: May 2001
Posts: 29,415
|
If that's like Julian date then also have a look at Perderabo's datecalc (unix.com)?
|
|
|
04-19-2009, 08:13 PM
|
#6
|
Member
Registered: Sep 2006
Distribution: MX-16 Modified using TDE
Posts: 239
Original Poster
Rep:
|
That's excellent!!!
Thank you unSpawn!
-Joe
|
|
|
04-19-2009, 08:17 PM
|
#7
|
Moderator
Registered: May 2001
Posts: 29,415
|
Heh, don't thank me, thank Perderabo.
|
|
|
04-19-2009, 08:29 PM
|
#8
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
This can be about a homework assignment, but I don't believe the question is to solve the assigment, but rather how to use tools. This is not a typical Linux question because there doesn't seem to be a textbook solution.
For any time calculations I recommend to use time stamps, or the number of seconds after 1970-01-01 00:00.
It is a weird format anyway, day 2 is 1900-01-01. I suppose somewhere there goes something wrong with leap centuries. (2000 was a leap year because it can be divided thru 400)
Anyway, 1970-01-01 has day number 25569 according to Calc.
1901-12-31 yields 731 in Calc
Difference 24838
If you use the date function: ts=$(date -d '1901-12-31' +%s)
$ts=-2146003200
-2146003200 / 24 / 3600 = -24838
Pretty close uh?
Unfortunately date doesn't accept dates earlier than 1901-12-31 so I can't prove that according to this calculation 1901-01-01 gets day number 2 but you get the idea.
Furthermore, date accepts offsets, e.g. to calculate a new date using an offset:
Code:
date -d '1971-12-31 + 365 days' +%Y-%m-%d
1972-12-30
Remember that bash doesn't do any floating point arithmetic, you can feed the result of date into dc so this becomes the complete function:
Code:
echo "$(date -d '1980-01-01' +%s) 3600 / 24 / 25569 + p" | sed s/'-'/'_'/ | dc
29221
The red part is the date string you want to convert. The sed in the formula above is to convert '-' to '_' which is needed to keep dc happy.
You can enter dates down to 1902-01-01.
jlinkels
|
|
|
04-19-2009, 08:30 PM
|
#9
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
Darn, unspawn was faster than me!
jlinkels
|
|
|
04-19-2009, 08:36 PM
|
#10
|
Moderator
Registered: Aug 2002
Posts: 26,743
|
Sorry for the misunderstanding.
Your question IMO did seem a bit vague and we had no way of knowing what 56778 actually represented or what you really meant by absolute. FYI Operating systems and applications do not use the same reference as starting points. linux uses seconds elapsed since 1/1/1970. Excel uses 12/31/1899 and it seems that OpenOffice uses 12/30/1899 as day 0.
|
|
|
04-19-2009, 08:46 PM
|
#11
|
Moderator
Registered: May 2001
Posts: 29,415
|
Quote:
Originally Posted by jlinkels
Darn, unspawn was faster than me!
|
That may be so but your elaborate solution is definately more interesting than me saying "look overthere".
|
|
|
04-19-2009, 08:56 PM
|
#12
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
Quote:
Originally Posted by unSpawn
That may be so but your elaborate solution is definately more interesting than me saying "look overthere".
|
Well... ok... this help to overcome my disappointment a bit
BTW, I haven't seen a date related question in this forum which could not be solved with date albeit not always uncomplicated or the most elegant solution. For calculating my wife's period it can be a day or so off.
jlinkels
|
|
|
04-19-2009, 08:57 PM
|
#13
|
Member
Registered: Sep 2006
Distribution: MX-16 Modified using TDE
Posts: 239
Original Poster
Rep:
|
Quote:
Originally Posted by michaelk
Sorry for the misunderstanding.
Your question IMO did seem a bit vague and we had no way of knowing what 56778 actually represented or what you really meant by absolute. FYI Operating systems and applications do not use the same reference as starting points. linux uses seconds elapsed since 1/1/1970. Excel uses 12/31/1899 and it seems that OpenOffice uses 12/30/1899 as day 0.
|
No offense taken; I hope none was given
I think that this does tie into the Julian calendar. Anyhow, the problem is solved.
Thanks,
-Joe
Last edited by joegumbo; 04-19-2009 at 09:03 PM.
|
|
|
04-19-2009, 08:59 PM
|
#14
|
Member
Registered: Sep 2006
Distribution: MX-16 Modified using TDE
Posts: 239
Original Poster
Rep:
|
jlinkels...
What can I say...
You are amazing!!!! 
Thanks!
-Joe
|
|
|
All times are GMT -5. The time now is 01:10 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|