LinuxQuestions.org
Help answer threads with 0 replies.
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
  Search this Thread
Old 06-09-2004, 01:06 PM   #1
chrisk5527
Member
 
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289

Rep: Reputation: 30
Subtracting dates


How can I subtract 2 days from 6/01/2004 and end up with 5/30/2004? I'm stuck.
 
Old 06-09-2004, 01:34 PM   #2
Nis
Member
 
Registered: Jul 2003
Location: Virginia
Distribution: Ubuntu Hoary (5.04)
Posts: 550

Rep: Reputation: 31
Code:
date --date='2 days ago' +%D
Direct from the date info pages. Some utilites use info pages instead of man pages so if the man page doesn't seem helpful try 'info command'
 
Old 06-09-2004, 01:58 PM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Maybe something along these lines..........

Code:
#!/bin/bash

then=`date +%B" "%d" "%Y -d "-2 day"`
now=`date +%B" "%d" "%Y`
tomorrow=`date +%B" "%d" "%Y -d "1 day"`


echo " Two days ago was $then"
echo " Todays date is $now"
echo " Tomorrows date is $tomorrow"
 
Old 06-10-2004, 01:02 PM   #4
chrisk5527
Member
 
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289

Original Poster
Rep: Reputation: 30
What I have is a filename such as 06012004_TEST_TEST and I'm trying to figure out what the Sunday date would be. I've been able to parse the filename out into month, day and year. It would be May 30th 2004, but how would I figure that out in a shell script? Any ideas?
 
Old 06-10-2004, 01:23 PM   #5
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
If you want to use shell scripts here is a resource for a lot of date shell code:

http://www.unix.com/showthread.php?s...ate+arithmetic
 
Old 06-10-2004, 02:07 PM   #6
chrisk5527
Member
 
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289

Original Poster
Rep: Reputation: 30
Thanks for that, but Im not sure anything in there answered my question. What I'm looking for is how to determine the date with another date For example, I have a date 6/01/2004 and I want to know the date of the prior Sunday which would be 5/30/2004. Another example would be 6/10/2004, the Sunday date would be 6/6/2004.

I would like something like
Code:
 date --date="6/7/2004"  "1 day ago"
and have it display 6/6/2004

Thanks.
 
Old 06-10-2004, 02:57 PM   #7
chrisk5527
Member
 
Registered: Oct 2002
Location: Michigan
Distribution: Slackware Linux 10.0
Posts: 289

Original Poster
Rep: Reputation: 30
I think I figured a solution out, but now I need to figure out how many days ago a date was. For example, 6/6/2004 was 4 days ago.

Last edited by chrisk5527; 06-10-2004 at 03:05 PM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtracting the day of two dates and recieving an integer answer(VB.NET) mrobertson Programming 1 08-15-2005 01:46 PM
f-spot dates viniosity Linux - Software 1 08-07-2005 07:43 PM
file dates digitalgravy Linux - General 2 01-20-2005 10:58 AM
File Dates Rv5 Programming 5 09-07-2004 05:59 PM
need to manipulate dates clsonnt Programming 5 08-19-2003 10:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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