Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date determination

Status
Not open for further replies.

meetramana

Programmer
Feb 2, 2005
57
US
Does any body have a quick idea about how to determine the date that was 300 days ago from the current date.
300 days is just an example.

I was wondering if there is quick thing that I didn't know.

Thanks
 
Have a look at this thread: thread52-1352399
There are some examples and links for determinining a past/future date.
 
a) Install postgres
b) create user etc.
c) create database util
d) create script datecalc.sh:
Code:
 psql util << EOF
CREATE TABLE u (d DATE);  
INSERT INTO u VALUES (now()); 
SELECT d$1 FROM u; 
DROP TABLE u;
EOF
run it like this:
Code:
 sh datacalc.sh -300
No bad idea, if a-c are already done.
With oracle, the magic dual-table should allow something like that:
Code:
select sysdate-300 from dual;
How to invoke a single ora-statement from shell has left my brain.
On Vista-Ultimate, you could easily do it with 217 mouseclicks, and access. :)

don't visit my homepage:
 
Hi

Stefan Wagner said:
How to invoke a single ora-statement from shell has left my brain.
Code:
echo 'select sysdate-300 from dual;' | sqlplus -S [green][i]username[/i][/green]/[green][i]password[/i][/green]@[green][i]database[/i][/green]

Feherke.
 
try date -d

or

perl -e
'@T=localtime(time-86400);printf("%02d/%02d/%02d",$T[4]+1,$T[3],($T[5]+1900) %100)'

where 86400 is seconds ago

300 days = 25920000 seconds

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
perl -e '@y=localtime(time - 86400 * 7 );printf "%s-%02d-%-02d\n",$y[5]+1900,$y[4]+1,$y[3];'

This works,
But How can I automate the with variable something similar to

perl -e '@y=localtime(time - 86400 * $DAYS );printf "%s-%02d-%-02d\n",$y[5]+1900,$y[4]+1,$y[3];'
 
I got it.

perl -e '@y=localtime(time() - 86400 * $ARGV[0] );printf "%s-%02d-%-02d\n",$y[5]+1900,$y[4]+1,$y[3];' $DAYS
 
Another way:
perl -e '@y=localtime(time - 86400 * [!]'[/!]$DAYS[!]'[/!] );printf "%s-%02d-%-02d\n",$y[5]+1900,$y[4]+1,$y[3];'

In your shell man page have a look at the "quoting" section.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top