Re: date/time calculation

2005-07-19 Thread Scott Leighton
On Monday 18 July 2005 10:09 am, Eko Budiharto wrote:
 Hi list,
 I have question. I got a piece of date data from mysql.
 Just saying, the data is 2005-06-05 00:00:00
 and then I would like to add it by 30 days
 it is supposed to be like this
 my $oldDate = 2005-06-05 00:00:00;
 my $newDate = $oldDate + 86400 * 30;

 but I confuse why it is not working. please help...

  Might be easier to simply let MySQL do the work for
you, e.g.,

 mysql select from_days(to_days('2005-06-05 00:00:00')+30);
+--+
| from_days(to_days('2005-06-05 00:00:00')+30) |
+--+
| 2005-07-05   |
+--+
1 row in set (0.00 sec)


   Scott

-- 
POPFile, the OpenSource EMail Classifier http://popfile.sourceforge.net/
Linux 2.6.11.4-21.7-default x86_64
SuSE Linux 9.3 (x86-64)
___
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: date/time calculation

2005-07-18 Thread eric clark
You are going to have to use something a bit more intelligent than the string you have. I would suggest changing the date to epoch seconds, and doing the conversion that way. This will account for a new month if the addition puts the date into the next month. Something like the following:
use Time::Local;
## Get the epoch seconds ##
## parse your original date with a regex in order to get the values for $day, $mon, $year
$epoch = timelocal( 0, 0, 12, $day, $mon, $year );$result = $epoch + (86400 * 30 );
( $day, $mon, $year ) = ( localtime( $epoch ) )[ 3, 4, 5 ];$year = $year + 1900;$mon = $mon + 1;$year = sprintf( "%04d", $year );$mon = sprintf( "%02d", $mon );$day = sprintf( "%02d", $day );$date = $year . "-" . $mon . "-" . $day;
This should work for you now, and this will take into account month changes, and other oddities like leap year.
Eric
"I'd take you seriously but to do so would be an affront to your intelligence."
-- William F. Buckley --
From: Eko Budiharto [EMAIL PROTECTED]To: activeperl@listserv.ActiveState.comSubject: date/time calculationDate: Mon, 18 Jul 2005 10:09:15 -0700 (PDT)MIME-Version: 1.0Received: from listserv.activestate.com ([209.17.183.249]) by mc7-f2.hotmail.com with Microsoft SMTPSVC(6.0.3790.211); Mon, 18 Jul 2005 10:51:32 -0700Received: from listserv.activestate.com (localhost.localdomain [127.0.0.1])by listserv.activestate.com (8.12.10/8.12.10) with ESMTP id j6IHOioD013709;Mon, 18 Jul 2005 10:24:51 -0700(envelope-from [EMAIL PROTECTED])Received: from smtp7.ActiveState.com (percolator.ActiveState.com[192.168.2.13])by listserv.activestate.com (8.12.10/8.12.10) with ESMTP idj6IH9Jl2012637 for activeperl@listserv.ActiveState.com;Mon, 18 Jul 2005 10:09:19 -0700(envelope-from 
[EMAIL PROTECTED])Received: from smtp8.activestate.com (smtp8.activestate.com [192.168.2.82])by smtp7.ActiveState.com (8.12.10/8.12.10) with ESMTP id j6IH9HxS010619for activeperl@listserv.ActiveState.com;Mon, 18 Jul 2005 10:09:18 -0700 (PDT)(envelope-from [EMAIL PROTECTED])Received: from web52907.mail.yahoo.com (web52907.mail.yahoo.com[206.190.49.17])by smtp8.activestate.com (8.13.3/8.13.3) with SMTP id j6IH9GDN075408for activeperl@listserv.ActiveState.com;Mon, 18 Jul 2005 10:09:17 -0700 (PDT)(envelope-from [EMAIL PROTECTED])Received: (qmail 52711 invoked by uid 60001); 18 Jul 2005 17:09:16 -Received: from [222.124.64.2] by web52907.mail.yahoo.com via HTTP;Mon, 18 Jul 2005 10:09:15 PDTX-Message-Info: JGTYoYF78jErcJqnCo9Ivzb+7zFDFv3cNNYXAPLjGEw=DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; 
d=yahoo.com;h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding;b=3K7N/MtdhT1bSLuuIWzHADcKPAOd+KaEKSF8sGtglFzl6+uT5F2JdYZhWYT3JSWCEBWKeZBkkaOjeMX7fkCZbImdqUOEqyLnD5plzMyDp18JtWK1oiEkNpvDpfNk4Ggz2ODEAlWfIsBgSvJmxNOdbKjlj+EYMp7cesKBfBuODYw=; X-PerlMx-Spam: CA, All, Gauge=XXIII, Probability=27%, Report='RCVD_IN_CBL 3,__CT 0, __CTE 0, __CTYPE_HAS_BOUNDARY 0, __CTYPE_MULTIPART 0,__CTYPE_MULTIPART_ALT 0, __DOMAINKEYS_YAHOO 0, __HAS_MSGID 0,__MIME_HTML 0, __MIME_VERSION 0, __SANE_MSGID 0,__STOCK_CRUFT 0'X-PMX-Version: CA 4.7.1.128075, Antispam-Engine: 2.0.3.2,Antispam-Data: 2005.7.18.18X-BeenThere: activeperl@listserv.ActiveState.comX-Mailman-Version: 2.1.4Precedence: listList-Id: Discussions relating to ActivePerlactiveperl.listserv.ActiveState.comList-Unsubscribe: 
http://listserv.ActiveState.com/mailman/listinfo/activeperl, mailto:[EMAIL PROTECTED]List-Archive: http://ASPN.ActiveState.com/ASPN/Mail/Browse/Threaded/activeperlList-Post: mailto:activeperl@listserv.ActiveState.comList-Help: mailto:[EMAIL PROTECTED]List-Subscribe: http://listserv.ActiveState.com/mailman/listinfo/activeperl, mailto:[EMAIL PROTECTED]Errors-To: [EMAIL PROTECTED]Return-Path: [EMAIL PROTECTED]X-OriginalArrivalTime: 18 Jul 2005 17:51:32.0683 (UTC) FILETIME=[5559E1B0:01C58BC1]Hi list,I have question. I got a piece of date data from mysql.Just saying, the 
data is 2005-06-05 00:00:00and then I would like to add it by 30 daysit is supposed to be like thismy $oldDate = "2005-06-05 00:00:00";my $newDate = $oldDate + 86400 * 30;but I confuse why it is not working. please help...__Do You Yahoo!?Tired of spam? Yahoo! Mail has the best spam protection aroundhttp://mail.yahoo.com___ActivePerl mailing listActivePerl@listserv.ActiveState.comTo unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

___
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: date/time calculation

2005-07-18 Thread Deane . Rothenmaier

Okay, for starters, you're trying to add an integer to a string. Perl will let you do this, but it reads the string until it finds something it can use as a number, then does so. That is, for your date string $oldDate, it finds 2005, uses that as the integer 2005, and adds 86400*30 to it. You need to convert your date string to some kind of number, like a Julian Day Number, do your addition, then convert it back to the string you want.

HTH,

Deane







Eko Budiharto [EMAIL PROTECTED]
Sent by: [EMAIL PROTECTED]
07/18/2005 12:09


To:activeperl@listserv.ActiveState.com
cc:
Subject:date/time calculation


Hi list,
I have question. I got a piece of date data from mysql.
Just saying, the data is 2005-06-05 00:00:00
and then I would like to add it by 30 days
it is supposed to be like this 
my $oldDate = 2005-06-05 00:00:00; 
my $newDate = $oldDate + 86400 * 30;

but I confuse why it is not working. please help...
__
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com ___
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

___
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs