Re: perl - MySQL - date manipulation

  • From: "Octavian Rasnita" <orasnita@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 28 Oct 2008 15:54:56 +0200

Hi,

If you need to do date calculations in perl, I would recommend using the 
modules Date::Calc, DateTime and Date::Manip. You can do extraordinary many 
things with them, very easy.

For example, if you have the year=2008, the month=10, and the day=15, and want 
to add 3 days, you can do:

Use Date::Calc qw(add_delta_days);

print Add_Delta_Days(2008, 10, 15, 3);

Octavian

----- Original Message ----- 
From: "Humberto Rodriguez" <sub@xxxxxxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Tuesday, October 28, 2008 3:12 PM
Subject: RE: perl - MySQL - date manipulation


> Hello Lamar:
> 
> Octavian has already told you very eloquently how to calculate dates in
> MYSQL and it is probably the preferred method.  I just want to add an easy
> method to do it in Perl.
> 
> You calculate localtime(time) which gives you the breakdown of now in local
> time, and it is just as easy to add to time the number of seconds into the
> future you desire, or substract the number of seconds into the past.  For
> instance, for a date 30 days in the future, you could say:
> 
> my ($sec, $min, $hour, $day, $mon, $year) = Localtime(time + 60 * 60 *24
> *30);
> 
> HTH,
> 
> Humberto
> 
> -----Original Message-----
> From: programmingblind-bounce@xxxxxxxxxxxxx
> [mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Lamar Upshaw
> Sent: Tuesday, October 28, 2008 6:30 AM
> To: programmingblind@xxxxxxxxxxxxx
> Subject: perl - MySQL - date manipulation
> 
> I'm working with perl and MySQL for CGI scripting, and I need to be able to 
> calculate dates. How do I have MySQL calculate 30 days from now, and return 
> it to perl? Or, would it be easier to calculate 30 days from now in perl 
> instead? I understand how to get the present date and time in perl, but I 
> can't figure out how to calculate other dates. Truthfully, I'd rather do 
> this in MySQL and have it return to perl, because the calculated date will 
> be saved in a database table whether I calculate it using perl, or MySQL 
> anyway.
> 
> With All Respect,
> Upshaw, Lamar T 
> 
> __________
> View the list's information and change your settings at 
> //www.freelists.org/list/programmingblind
> 
> 
> __________
> View the list's information and change your settings at 
> //www.freelists.org/list/programmingblind
>
__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind

Other related posts: