LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-07-2009, 10:18 PM   #1
mikejreading
LQ Newbie
 
Registered: May 2009
Posts: 24

Rep: Reputation: 0
Question Calculating the difference between two dates


Sorry guys,

Its late, and my brain isnt working.

Im trying to calculate the difference between two dates.

Doing this by taking Todays date is subtracting it from the Target date.

Im getting todays date with date +%s to get time since the epoch, but how do i convert the other time to it?

(there are a few examples, one of which is time since the last boot)

Using the command who -b how do i convert into UNIX time? (Or is there a better way of doing it?)

Cheers
 
Old 05-08-2009, 10:22 AM   #2
berbae
Member
 
Registered: Jul 2005
Location: France
Distribution: Arch Linux
Posts: 540

Rep: Reputation: Disabled
In 'man date' :
Quote:
-d, --date=STRING
display time described by STRING, not `now'
So to convert the date from the 'who -b' command, you can do something like :

date -d "$(who -b|tr -s " "|cut -d " " -f 4-)" +%s

The 'tr' command eliminates the multiple spaces at the start of the output string, and the 'cut' command extracts only the date and time.
$(...) gives the output of the command inside it.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between two dates Uday123 Programming 5 02-23-2009 07:26 AM
Calculating seconds newbie_adm Programming 8 10-21-2008 01:29 PM
calculating throughput ilnli Programming 6 07-17-2007 02:58 AM
calculating in bash ovince Programming 3 03-28-2007 11:50 AM
calculating buffer size cynthia_thomas Programming 1 01-19-2006 11:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:38 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration