RE: perl - MySQL - date manipulation

  • From: "Humberto Rodriguez" <sub@xxxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Tue, 28 Oct 2008 09:12:09 -0400

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

Other related posts: