Shell scripting for date validation

Red hat Linux 7.3 personal
April 7, 2010 at 19:11:05
Specs: Windows 7
hi i need to get a solution for date validation function.
the thing is i have to get the output for previous date from system date and currernt date and future date
. i m using borne shell

See More: Shell scripting for date validation

Report •

#1
April 8, 2010 at 16:14:43
If you are using RedHat, you can type 'info date' to get info on this.

#!/bin/sh
echo "Using system time:"
echo "5 years ago: $(date +%D --date='5 years ago')"
echo "4 month ago: $(date +%D --date='4 months ago')"
echo "3 weeks ago: $(date +%D --date='3 weeks ago')"
echo " 2 days ago: $(date +%D --date='2 days ago')"
echo " Yesterday: $(date +%D --date='1 days ago')"
echo " Today Date: $(date +%D)"
echo " Tomorrow: $(date +%D --date='1 day')"
echo " In 2 days: $(date +%D --date='2 days')"
echo " In 1 week: $(date +%D --date='1 week')"
echo " In 1 month: $(date +%D --date='1 month')"
echo " In 1 year: $(date +%D --date='1 year')"
echo "1y,2m,3w 4d: $(date +%D --date='1 year 2 months 3 weeks 4 days')"
echo
echo "Using February 27, 2004 as the base date:"
echo " Yesterday: $(date +%D --date="2004-02-27 yesterday")"
echo " Today: $(date +%D --date="2004-02-27")"
echo " Tomorrow: $(date +%D --date="2004-02-27 tomorrow")"
echo " In 2 days: $(date +%D --date="2004-02-27 2 days")"


The output:
Using system time:
5 years ago: 04/07/05
4 month ago: 12/07/09
3 weeks ago: 03/17/10
2 days ago: 04/05/10
Yesterday: 04/06/10
Today Date: 04/07/10
Tomorrow: 04/08/10
In 2 days: 04/09/10
In 1 week: 04/14/10
In 1 month: 05/07/10
In 1 year: 04/07/11
1y,2m,3w 4d: 07/02/11

Using February 27, 2004 as the base date:
Yesterday: 02/26/04
Today: 02/27/04
Tomorrow: 02/28/04
In 2 days: 02/29/04


Report •

#2
April 14, 2010 at 09:50:19
If you are using RedHat...

If he's using RedHat he should be in the "Linux" forum. Excuse me for pointing out the obvious but this IS the Unix forum after all....


Report •
Related Solutions


Ask Question