LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Subtracting dates (http://www.linuxquestions.org/questions/linux-general-1/subtracting-dates-191564/)

chrisk5527 06-09-2004 01:06 PM

Subtracting dates
 
How can I subtract 2 days from 6/01/2004 and end up with 5/30/2004? I'm stuck.

Nis 06-09-2004 01:34 PM

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'

homey 06-09-2004 01:58 PM

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"


chrisk5527 06-10-2004 01:02 PM

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?

jim mcnamara 06-10-2004 01:23 PM

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

chrisk5527 06-10-2004 02:07 PM

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.

chrisk5527 06-10-2004 02:57 PM

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.


All times are GMT -5. The time now is 09:33 AM.