The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sysdate -1 in unix kskywr UNIX for Dummies Questions & Answers 1 04-12-2007 09:53 AM
sysdate -p -f%d/%m/%Y abu_hassan UNIX for Dummies Questions & Answers 1 02-11-2007 09:26 AM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr HP-UX 1 10-16-2006 01:16 PM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr Shell Programming and Scripting 0 09-19-2006 06:44 PM
How to get sysdate -1 gopskrish UNIX for Dummies Questions & Answers 2 06-23-2005 03:38 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 08-27-2001
Registered User
 

Join Date: Aug 2001
Location: Peru
Posts: 5
Getting sysdate - 2 by an unix command

How can I get an equivalent in unix for the following Oracle SQL command:

select sysdate - 2 from dual;


Thanks

José
__________________
José
Forum Sponsor
  #2  
Old 08-27-2001
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584

Here is one way:


#!/usr/bin/sh
_day=`date +%d`
_month=`date +%m`
_year=`date +%y`
newday=`expr $_day - 2`
echo "Two days ago was $_month/$newday/$_year "


I know the GNU date provides an easier way, but this is more portable...

your to_char function is up to you :P
  #3  
Old 08-28-2001
PxT's Avatar
PxT PxT is offline
Registered User
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
Except if you run it on the 1st, then 1-2 = -1. Oops.

A portable solution is to convert the current date to a julian value, subtract 2 and then convert back to a gregorian value. A script to convert to/from julian date is here: http://droflet.net/julian.txt

Last edited by PxT; 08-28-2001 at 11:49 AM.
  #4  
Old 08-31-2001
Registered User
 

Join Date: Aug 2001
Posts: 3
this login does not work with number greater than the days passed in the going month.
plz try this script it will fail .

#!/usr/bin/sh
echo "Plz enter the number of diff required"
read _diff
_day=`date +%d`
_month=`date +%m`
_year=`date +%y`
newday=`expr $_day - $_diff`
echo "Two days ago was $_month/$newday/$_year "
  #5  
Old 08-31-2001
LivinFree's Avatar
Goober Extraordinaire
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584

Yeah, that is the shortcoming that PxT pointed out in my script also. I like his idea better of converting to julian date, subtracting the number you need, then converting back to regular date. Please check out his script - it's much better, and is less likely to contain the simple errors I have included (as features, of course) in mine.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0