Dating 24date inmy
# Tapani Tarvainen January 2002 # This code is in the public domain. $ date --date='1 day ago' - amber ---July 13, 2004 Thanks Amber! /bin/bash OFFSET=1; eval `date " day=%d; month=%m; year=%Y"` # Subtract offset from day, if it goes below one use 'cal' # to determine the number of days in the previous month.It's only true on Linux, but that does point out the importance of reading "info date" instead of just "man date" - you won't find that option spelled out fully in the man page, but the info doc does explain it. day=`expr $day - $OFFSET` if [ $day -le 0 ] ;then month=`expr $month - 1` if [ $month -eq 0 ] ;then year=`expr $year - 1` month=12 fi set `cal $month $year` xday=$ day=`expr $xday $day` fi echo $year-$month-$day P.s.= i'm sorry but this editing loss indentation -- stetor ---December 13, 2004 ---December 28, 2004 Hi, My problem is that i want to compute a date (before or after) based on a fixed date.
# Tapani Tarvainen January 2002 # This code is in the public domain. I wasn't reinventiing the wheel and I didn't say that it was 100 percent reliable.
Context, long, int)) and [format Date Range()]( Utils.html#format Date Range(android.content.
Context, long, long, int)) - which take in flags to determine which fields to include.
If the month is now 0, make it 12..") but that's cumbersome and seldom needed. BSD systems like Mac OS X don't have that, but they do have "-v" modifiers, and although I may be a bit prejudiced, I like them better. For yesterday: # I did this on April 19th, 2011 $ date -v2010y # move to 2010 Mon Apr 19 EDT 2010 $ date -v2010y -v3m # and then to March Fri Mar 19 EDT 2010 $ date -v2010y -v3m -v1d # and then to March 1st Mon Mar 1 EST 2010 $ date -v2010y -v3m -v1d -v-1d # now go back one day Sun Feb 28 EST 2010 $ date -v2008y -v3m -v1d -v-1d # same thing for 2008 (a leap year) Fri Feb 29 EST 2008 Before we look at some of the more difficult ways to manipulate dates, a word of caution is in order: when people ask for something from "yesterday" or "last week", the answer isn't always to subtract one day or seven for a week.
We can do this using already existing Unix/Linux tools. This is GNU date, and you won't find these options in "man date" - you have to use "info date" (or "pinfo date" if you hate emacs as I do). "Last week" can easily mean anything after a week back from the preceding Monday or Sunday - it's more likely to mean that than a strict "7 days back".