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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with date's (+/- operations with date)

Status
Not open for further replies.

1yura1

Programmer
Feb 7, 2003
36
UA
Hi all!
I need to make next operation in perl:
Currient_date - one_day
For example: 01.05.2003 - 1 = 30.04.2003

How can I do this?

 
Hello, I also need to do something similar.

I need to be able to increment a date by a month, a quarter and a year.

Eg: 1/4/03 - 1/5/03 - 1/7/03 - 1/4/04

Any ideas?

Simon
 
Hi folks,

I'm really struggling with this one!

I think I need to use this:

($year,$month,$day) = Add_Delta_YMD($year,$month,$day, $Dy,$Dm,$Dd);

but don't really know how to add it to my perl script!?

Basically, I need to add 1 month to the current date (today's date).

Can anyone jump in here!?

Simon
 
use Date::Calc;

$now = Date::Calc->now();
$now += [0,1,0,0,0,0];

I took this from one of the examples in the documentation, the actual example was:


# Switch to summer time:
$now = Date::Calc->now();
if (($now ge [2000,3,26,2,0,0]) and
($now lt [2000,3,26,3,0,0]))
{
$now += [0,0,0,1,0,0];
}

The eg adds 1 to the hour, so I changed it a little to add 1 to the month number. Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Hi Mike,

Thanks for that snippet. Unfortunately, I'm getting:

Can't locate auto/Date/Calc/now.al

in my error logs which I'm going to have to check out.

But thanks again!

Simon
 
ahhh- sorted!

changed:

use Date::Calc;

to:

use Date::Calc::Object qw:)all);

Thanks again Mike
 
Hi all :)

Try to dy smth. like this:
use Time::Local;

sub yesterday {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime;
my $time_in_sec = timelocal($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
$time_in_sec = $time_in_sec - 86400; #60*60*24 - one day in sec.
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($time_in_sec);

$mon=$mon+1;
$year=$year+1900;
if( length(trim($mday))<2 ) { $mday = &quot;0&quot;.$mday }
if( length(trim($mon))<2 ) { $mon = &quot;0&quot;.$mon }
return $mday.$mon.$year;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top