How to get yesterday's date in Perl

--===============1294046017==
Content-Type: multipart/alternative; boundary="0-1991246789-1228305870=:92784"

--0-1991246789-1228305870=:92784
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable


After brouwsing=A0a lot ofdocumentation I cannot find how to get yesterday'=
s or tomorrow's date in Perl, like `date --date "-1 day" "+%Y%m%d"` in bash=
.. Is this possible in Perl?
I am making date directories, like 20081203. If I add, I get a problem at t=
he end/begining of the month, I get like 20081131 or 20081200.
Thanks for any assistance.
Zilore
=0A=0A=0A
--0-1991246789-1228305870=:92784
Content-Type: text/html; charset=us-ascii

<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV><BR>After brouwsing a lot ofdocumentation I cannot find how to get yesterday's or tomorrow's date in Perl, like `date --date "-1 day" "+%Y%m%d"` in bash. Is this possible in Perl?</DIV>
<DIV>I am making date directories, like 20081203. If I add, I get a problem at the end/begining of the month, I get like 20081131 or 20081200.</DIV>
<DIV>Thanks for any assistance.</DIV>
<DIV>Zilore<BR></DIV></td></tr></table><br>


--0-1991246789-1228305870=:92784--

--===============1294046017==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1294046017==--
zilore mumba [ Mi, 03 Dezember 2008 13:04 ] [ ID #1979567 ]

Re: How to get yesterday's date in Perl

From: zilore mumba <zmumba [at] yahoo.com>
> After brouwsing=A0a lot ofdocumentation I cannot find how to get
> yesterday's or tomorrow's date in Perl, like `date --date "-1 day"
> "+%Y%m%d"` in bash. Is this possible in Perl? =

>
> I am making date directories, like 20081203. If I add, I get a problem
> at the end/begining of the month, I get like 20081131 or 20081200. =

>
> Thanks for any assistance.
> Zilore

time() returns the number of seconds since some date. localtime() =

formats or returns the individual parts of a date and does so either =

for the current date&time or for some date in the format of the =

number of seconds since the same date as time(). So in this =

particular case (and if you do not mind summer/winter-time changes) =

all you have to do is to pass time()+dayload_of_seconds to =

localtime(). And since you do not use the hour and minute you do not =

mind summer/winter-time.

If you need something more complex have a look at the DateTime module =

(http://search.cpan.org/search?query=3DDateTime&mode=3Dall)

Jenda
=3D=3D=3D=3D=3D Jenda [at] Krynicky.cz =3D=3D=3D http://Jenda.Krynicky.cz =3D=3D=
=3D=3D=3D
When it comes to wine, women and song, wizards are allowed =

to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Jenda Krynicky [ Mi, 03 Dezember 2008 13:17 ] [ ID #1979568 ]

Re: How to get yesterday's date in Perl

This is a multi-part message in MIME format.
--------------080204050504080502000900
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

time - 24*60*60 is a quick guess

zilore mumba wrote:
>
> After brouwsing a lot ofdocumentation I cannot find how to get
> yesterday's or tomorrow's date in Perl, like `date --date "-1 day"
> "+%Y%m%d"` in bash. Is this possible in Perl?
> I am making date directories, like 20081203. If I add, I get a problem
> at the end/begining of the month, I get like 20081131 or 20081200.
> Thanks for any assistance.

--------------080204050504080502000900
Content-Type: text/x-vcard; charset=utf-8;
name="angelos.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="angelos.vcf"

begin:vcard
fn:Angelos Karageorgiou
n:Karageorgiou;Angelos
org:Vivodi Telecommunications S.A.
email;internet:angelos [at] unix.gr
title:Technology Manager
tel;work:+30 211 7503 893
tel;fax:+30 211 7503 701
tel;cell:+30 6949120773
note;quoted-printable:=0D=0A=
=0D=0A=
Linkedin Profile =
=0D=0A=
http://www.linkedin.com/in/unixgr=0D=0A=
=0D=0A=
=0D=0A=
=0D=0A=
Personal Web Site=0D=0A=
http://www.unix.gr=0D=0A=
=0D=0A=
=0D=0A=
Blog Site=0D=0A=
http://angelos-proverbs.blogspot.com
x-mozilla-html:FALSE
url:http://www.linkedin.com/in/unixgr
version:2.1
end:vcard


--------------080204050504080502000900
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--------------080204050504080502000900--
Angelos Karageorgiou [ Mi, 03 Dezember 2008 13:56 ] [ ID #1979569 ]

RE: How to get yesterday's date in Perl

This is a multi-part message in MIME format.

--===============0358820505==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C9554F.C75B0427"

This is a multi-part message in MIME format.

------_=_NextPart_001_01C9554F.C75B0427
Content-Type: text/plain;
charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

Hello

use Date::Calc qw(Add_Delta_Days)

Erich

________________________________

From: activeperl-bounces [at] listserv.ActiveState.com
[mailto:activeperl-bounces [at] listserv.ActiveState.com] On Behalf Of zilore
mumba
Sent: Wednesday, December 03, 2008 7:05 AM
To: activeperl [at] listserv.activestate.com
Subject: How to get yesterday's date in Perl



After brouwsing a lot ofdocumentation I cannot find how to get
yesterday's or tomorrow's date in Perl, like `date --date "-1 day"
"+%Y%m%d"` in bash. Is this possible in Perl?
I am making date directories, like 20081203. If I add, I get a problem
at the end/begining of the month, I get like 20081131 or 20081200.
Thanks for any assistance.
Zilore



------_=_NextPart_001_01C9554F.C75B0427
Content-Type: text/html;
charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.2800.1607" name=3DGENERATOR></HEAD>
<BODY>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D640050114-03122008><FONT =
face=3DArial
color=3D#0000ff size=3D2>Hello</FONT></SPAN></DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D640050114-03122008><FONT =
face=3DArial
color=3D#0000ff size=3D2></FONT></SPAN> </DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D640050114-03122008><FONT =
face=3DArial
color=3D#0000ff size=3D2>use Date::Calc =
qw(Add_Delta_Days)</FONT></SPAN></DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D640050114-03122008><FONT =
face=3DArial
color=3D#0000ff size=3D2></FONT></SPAN> </DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D640050114-03122008><FONT =
face=3DArial
color=3D#0000ff size=3D2>Erich</FONT></SPAN></DIV><BR>
<DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr align=3Dleft>
<HR tabIndex=3D-1>
<FONT face=3DTahoma size=3D2><B>From:</B>
activeperl-bounces [at] listserv.ActiveState.com
[mailto:activeperl-bounces [at] listserv.ActiveState.com] <B>On Behalf Of =
</B>zilore
mumba<BR><B>Sent:</B> Wednesday, December 03, 2008 7:05 AM<BR><B>To:</B> =

activeperl [at] listserv.activestate.com<BR><B>Subject:</B> How to get =
yesterday's
date in Perl<BR></FONT><BR></DIV>
<DIV></DIV>
<TABLE cellSpacing=3D0 cellPadding=3D0 border=3D0>
<TBODY>
<TR>
<TD vAlign=3Dtop>
<DIV><BR>After brouwsing a lot ofdocumentation I cannot find =
how to
get yesterday's or tomorrow's date in Perl, like `date --date "-1 =
day"
"+%Y%m%d"` in bash. Is this possible in Perl?</DIV>
<DIV>I am making date directories, like 20081203. If I add, I get =
a
problem at the end/begining of the month, I get like 20081131 or
20081200.</DIV>
<DIV>Thanks for any assistance.</DIV>
<DIV>Zilore<BR></DIV></TD></TR></TBODY></TABLE><BR></BODY></HTML>

------_=_NextPart_001_01C9554F.C75B0427--

--===============0358820505==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0358820505==--
Erich.Singer [ Mi, 03 Dezember 2008 15:03 ] [ ID #1979570 ]

RE: How to get yesterday's date in Perl

--===============0017052296==
Content-Type: multipart/alternative; boundary="0-2108951000-1228316947=:11747"

--0-2108951000-1228316947=:11747
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

thanks for the response, but it is still not clear to me. What do I put in =
qw(Add_Delta_Days)?
Thanks
Zilore



--- On Wed, 12/3/08, Singer, Erich <Erich.Singer [at] starcompliance.com> wrote:

From: Singer, Erich <Erich.Singer [at] starcompliance.com>
Subject: RE: How to get yesterday's date in Perl
To: zmumba [at] yahoo.com, activeperl [at] listserv.activestate.com
Date: Wednesday, December 3, 2008, 4:03 PM



Hello
=A0
use Date::Calc qw(Add_Delta_Days)
=A0
Erich



From: activeperl-bounces [at] listserv.ActiveState.com [mailto:activeperl-bounce=
s [at] listserv.ActiveState.com] On Behalf Of zilore mumba
Sent: Wednesday, December 03, 2008 7:05 AM
To: activeperl [at] listserv.activestate.com
Subject: How to get yesterday's date in Perl








After brouwsing=A0a lot ofdocumentation I cannot find how to get yesterday'=
s or tomorrow's date in Perl, like `date --date "-1 day" "+%Y%m%d"` in bash=
.. Is this possible in Perl?
I am making date directories, like 20081203. If I add, I get a problem at t=
he end/begining of the month, I get like 20081131 or 20081200.
Thanks for any assistance.
Zilore

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs=0A=0A=0A =

--0-2108951000-1228316947=:11747
Content-Type: text/html; charset=us-ascii

<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>thanks for the response, but it is still not clear to me. What do I put in qw(<FONT color=#0000ff>Add_Delta_Days)?</FONT></DIV>
<DIV><FONT color=#0000ff>Thanks</FONT></DIV>
<DIV><FONT color=#0000ff>Zilore</FONT><BR><BR><BR><BR>--- On <B>Wed, 12/3/08, Singer, Erich <I><Erich.Singer [at] starcompliance.com></I></B> wrote:<BR></DIV>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(16,16,255) 2px solid">From: Singer, Erich <Erich.Singer [at] starcompliance.com><BR>Subject: RE: How to get yesterday's date in Perl<BR>To: zmumba [at] yahoo.com, activeperl [at] listserv.activestate.com<BR>Date: Wednesday, December 3, 2008, 4:03 PM<BR><BR>
<DIV id=yiv1154962195>
<DIV dir=ltr align=left><SPAN class=640050114-03122008><FONT face=Arial color=#0000ff size=2>Hello</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=640050114-03122008><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=640050114-03122008><FONT face=Arial color=#0000ff size=2>use Date::Calc qw(Add_Delta_Days)</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=640050114-03122008><FONT face=Arial color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=640050114-03122008><FONT face=Arial color=#0000ff size=2>Erich</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> activeperl-bounces [at] listserv.ActiveState.com [mailto:activeperl-bounces [at] listserv.ActiveState.com] <B>On Behalf Of </B>zilore mumba<BR><B>Sent:</B> Wednesday, December 03, 2008 7:05 AM<BR><B>To:</B> activeperl [at] listserv.activestate.com<BR><B>Subject:</B> How to get yesterday's date in Perl<BR></FONT><BR></DIV>
<DIV></DIV>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TD vAlign=top>
<DIV><BR>After brouwsing a lot ofdocumentation I cannot find how to get yesterday's or tomorrow's date in Perl, like `date --date "-1 day" "+%Y%m%d"` in bash. Is this possible in Perl?</DIV>
<DIV>I am making date directories, like 20081203. If I add, I get a problem at the end/begining of the month, I get like 20081131 or 20081200.</DIV>
<DIV>Thanks for any assistance.</DIV>
<DIV>Zilore<BR></DIV></TD></TR></TBODY></TABLE><BR></DIV><PRE>_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs</PRE></BLOCKQUOTE></td></tr></table><br>


--0-2108951000-1228316947=:11747--

--===============0017052296==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0017052296==--
zilore mumba [ Mi, 03 Dezember 2008 16:09 ] [ ID #1979571 ]

RE: How to get yesterday's date in Perl

--===============0723490091==
Content-Language: en-US
Content-Type: multipart/alternative;
boundary="_000_62432006F5965C42BAEC4EA29286EE0507B180EDF7EXC MS01westat_"

--_000_62432006F5965C42BAEC4EA29286EE0507B180EDF7EXCMS01west at_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

#!/usr/bin/perl -w

use strict ;
use Date::Calc qw(Add_Delta_Days) ;

my ( $todayd, $todaym, $todayy ) =3D (localtime)[3..5] ;
$todaym +=3D 1 ;
$todayy +=3D 1900 ;

my ($yesty,$yestm,$yestd) =3D Add_Delta_Days($todayy,$todaym,$todayd, -1) ;

print "Today:\t\t$todaym/$todayd/$todayy\nYesterday:\t$yestm/$yest d/$yesty\=
n" ;

--
Henry

-----Original Message-----
From: activeperl-bounces [at] listserv.ActiveState.com [mailto:activeperl-bounce=
s [at] listserv.ActiveState.com] On Behalf Of zilore mumba
Sent: Wednesday, December 03, 2008 10:09 AM
To: activeperl [at] listserv.activestate.com
Subject: RE: How to get yesterday's date in Perl

thanks for the response, but it is still not clear to me. What do I put in =
qw(Add_Delta_Days)?
Thanks
Zilore



--- On Wed, 12/3/08, Singer, Erich <Erich.Singer [at] starcompliance.com> wrote:
From: Singer, Erich <Erich.Singer [at] starcompliance.com>
Subject: RE: How to get yesterday's date in Perl
To: zmumba [at] yahoo.com, activeperl [at] listserv.activestate.com
Date: Wednesday, December 3, 2008, 4:03 PM

Hello

use Date::Calc qw(Add_Delta_Days)

Erich

________________________________
From: activeperl-bounces [at] listserv.ActiveState.com [mailto:activeperl-bounce=
s [at] listserv.ActiveState.com] On Behalf Of zilore mumba
Sent: Wednesday, December 03, 2008 7:05 AM
To: activeperl [at] listserv.activestate.com
Subject: How to get yesterday's date in Perl


After brouwsing a lot ofdocumentation I cannot find how to get yesterday's =
or tomorrow's date in Perl, like `date --date "-1 day" "+%Y%m%d"` in bash. =
Is this possible in Perl?
I am making date directories, like 20081203. If I add, I get a problem at t=
he end/begining of the month, I get like 20081131 or 20081200.
Thanks for any assistance.
Zilore



_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



--_000_62432006F5965C42BAEC4EA29286EE0507B180EDF7EXCMS01west at_
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Message</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.2900.5659" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2>#!/usr/bin/perl -w</FONT><=
/DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2>use strict ;<BR>use Date::=
Calc
qw(Add_Delta_Days) ;</FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2>my ( $<SPAN
class=3D546271616-03122008>today</SPAN>d, $<SPAN
class=3D546271616-03122008>today</SPAN>m, $<SPAN
class=3D546271616-03122008>today</SPAN>y ) =3D (localtime)[3..5] ;<BR>$<SPA=
N
class=3D546271616-03122008>today</SPAN>m +=3D 1 ;<BR>$<SPAN
class=3D546271616-03122008>today</SPAN>y  +=3D 1900 ;</FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2>my ($<SPAN
class=3D546271616-03122008>yest</SPAN>y,$<SPAN
class=3D546271616-03122008>yest</SPAN>m,$<SPAN
class=3D546271616-03122008>yest</SPAN>d) =3D Add_Delta_Days($<SPAN
class=3D546271616-03122008>today</SPAN>y,$<SPAN
class=3D546271616-03122008>todaym</SPAN>,$<SPAN
class=3D546271616-03122008>today</SPAN>d, -1) ;</FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2>print "Today:\t\t$<SPAN
class=3D546271616-03122008>today</SPAN>m/$<SPAN
class=3D546271616-03122008>today</SPAN>d/$<SPAN
class=3D546271616-03122008>today</SPAN>y\nYesterday:\t$<SPAN
class=3D546271616-03122008>yest</SPAN>m/$<SPAN
class=3D546271616-03122008>yest</SPAN>d/$<SPAN
class=3D546271616-03122008>yest</SPAN>y\n" ;</FONT></DIV>
<DIV><FONT face=3DArial color=3D#0000ff size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>--<BR>Henry</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV></DIV>
<DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr align=3Dleft><FONT=
face=3DTahoma
size=3D2>-----Original Message-----<BR><B>From:</B>
activeperl-bounces [at] listserv.ActiveState.com
[mailto:activeperl-bounces [at] listserv.ActiveState.com] <B>On Behalf Of </B>zi=
lore
mumba<BR><B>Sent:</B> Wednesday, December 03, 2008 10:09 AM<BR><B>To:</B>
activeperl [at] listserv.activestate.com<BR><B>Subject:</B> RE: How to get
yesterday's date in Perl<BR><BR></FONT></DIV>
<TABLE cellSpacing=3D0 cellPadding=3D0 border=3D0>
<TBODY>
<TR>
<TD vAlign=3Dtop>
<DIV>thanks for the response, but it is still not clear to me. What d=
o I
put in qw(<FONT color=3D#0000ff>Add_Delta_Days)?</FONT></DIV>
<DIV><FONT color=3D#0000ff>Thanks</FONT></DIV>
<DIV><FONT color=3D#0000ff>Zilore</FONT><BR><BR><BR><BR>--- On <B>Wed=
,
12/3/08, Singer, Erich <I><Erich.Singer [at] starcompliance.com></I>=
</B>
wrote:<BR></DIV>
<BLOCKQUOTE
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(16,16,=
255) 2px solid">From:
Singer, Erich <Erich.Singer [at] starcompliance.com><BR>Subject: R=
E:
How to get yesterday's date in Perl<BR>To: zmumba [at] yahoo.com,
activeperl [at] listserv.activestate.com<BR>Date: Wednesday, December 3,=

2008, 4:03 PM<BR><BR>
<DIV id=3Dyiv1154962195>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D640050114-03122008><FONT =
face=3DArial
color=3D#0000ff size=3D2>Hello</FONT></SPAN></DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D640050114-03122008><FONT =
face=3DArial
color=3D#0000ff size=3D2></FONT></SPAN> </DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D640050114-03122008><FONT =
face=3DArial
color=3D#0000ff size=3D2>use Date::Calc
qw(Add_Delta_Days)</FONT></SPAN></DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D640050114-03122008><FONT =
face=3DArial
color=3D#0000ff size=3D2></FONT></SPAN> </DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D640050114-03122008><FONT =
face=3DArial
color=3D#0000ff size=3D2>Erich</FONT></SPAN></DIV><BR>
<DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr align=3Dle=
ft>
<HR tabIndex=3D-1>
<FONT face=3DTahoma size=3D2><B>From:</B>
activeperl-bounces [at] listserv.ActiveState.com
[mailto:activeperl-bounces [at] listserv.ActiveState.com] <B>On Behalf O=
f
</B>zilore mumba<BR><B>Sent:</B> Wednesday, December 03, 2008 7:05=

AM<BR><B>To:</B> activeperl [at] listserv.activestate.com<BR><B>Subject:=
</B>
How to get yesterday's date in Perl<BR></FONT><BR></DIV>
<DIV></DIV>
<TABLE cellSpacing=3D0 cellPadding=3D0 border=3D0>
<TBODY>
<TR>
<TD vAlign=3Dtop>
<DIV><BR>After brouwsing a lot ofdocumentation I cannot =
find
how to get yesterday's or tomorrow's date in Perl, like `date=

--date "-1 day" "+%Y%m%d"` in bash. Is this possible in
Perl?</DIV>
<DIV>I am making date directories, like 20081203. If I add, I=
get
a problem at the end/begining of the month, I get like 200811=
31 or
20081200.</DIV>
<DIV>Thanks for any assistance.</DIV>
<DIV>Zilore<BR></DIV></TD></TR></TBODY></TABLE><BR></DIV><PRE=
>_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs</PRE></BLOCK=
QUOTE></TD></TR></TBODY></TABLE><BR></BODY></HTML>

--_000_62432006F5965C42BAEC4EA29286EE0507B180EDF7EXCMS01west at_--

--===============0723490091==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0723490091==--
Henry Hartley [ Mi, 03 Dezember 2008 17:18 ] [ ID #1979572 ]

RE: How to get yesterday's date in Perl

> After browsing a lot of documentation I cannot find how to get
yesterday's or tomorrow's date in Perl, like `date --date "-1 day"
"+%Y%m%d"` in bash.

localtime() takes an epoc number (number of seconds from 1/1/1970) and
produces either the date data list (perldoc -f localtime)::
# 0 1 2 3 4 5 6 7 8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =

localtime(time);

- where 'time()' produces the current epoch number ("1228321233" as I type)
or, in scalar context, a nicely formated date string:
$ perl -e 'print time() . "\n"'
1228321233
$ perl -e 'print localtime() . "\n"'
Wed Dec 3 10:21:23 2008

(by default, 'time()' is the param for localtime() ). So you can get the
values for yest by subtracting 1 day worth of seconds:
my ($mday, $mon, $year) = (localtime(time() - 60 * 60 * 24) ) [ 3,4,5];
printf("%d/%02d/%02d\n", $year + 1900, $mon + 1, $mday - 1);

- note, month is zero based (hence the +1) and year is given as of 1900
(that is, the value for 2008 is 108). If you want a 2 digit year, you need
to mod by 100.

Otherwise there's the core module POSIX which include strftime which lets
you use the full bash/unix 'date' command's format strings. See perldoc
POSIX for details.

a
-------------------
Andy Bach
Systems Mangler
Internet: andy_bach [at] wiwb.uscourts.gov
Voice: (608) 261-5738 Fax: 264-5932

If I have seen farther than others, it is because I was standing on the
shoulders of giants. -- Isaac Newton
In the sciences, we are now uniquely privileged to sit side by side
with the giants on whose shoulders we stand. -- Gerald
Holton
If I have not seen as far as others, it is because giants were standing
on my shoulders. -- Hal Abelson
In computer science, we stand on each other's feet. -- Brian
K. Reid

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Andy_Bach [ Mi, 03 Dezember 2008 17:28 ] [ ID #1979573 ]

RE: How to get yesterday's date in Perl

Andy_Bach [at] wiwb.uscourts.gov wrote:

>> (by default, 'time()' is the param for localtime() ). So you can
>> get the values for yest by subtracting 1 day worth of seconds:
>> my ($mday, $mon, $year) = (localtime(time() - 60 * 60 * 24) ) [ 3,4,5];
>> printf("%d/%02d/%02d\n", $year + 1900, $mon + 1, $mday - 1);

Will there be a time when that's wrong due to daylight saving time changes?

--
Henry
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Henry Hartley [ Mi, 03 Dezember 2008 17:34 ] [ ID #1979574 ]

Re: How to get yesterday's date in Perl

On Dec 3, 2008, at 8:34 , Henry Hartley wrote:

> Andy_Bach [at] wiwb.uscourts.gov wrote:
>
>>> (by default, 'time()' is the param for localtime() ). So you can
>>> get the values for yest by subtracting 1 day worth of seconds:
>>> my ($mday, $mon, $year) = (localtime(time() - 60 * 60 * 24) )
>>> [ 3,4,5];
>>> printf("%d/%02d/%02d\n", $year + 1900, $mon + 1, $mday - 1);
>
> Will there be a time when that's wrong due to daylight saving time
> changes?

Yes. There are 2 hours each year when this formula is wrong.

--Gisle

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Gisle Aas [ Mi, 03 Dezember 2008 18:26 ] [ ID #1979575 ]

Re: How to get yesterday's date in Perl

This is a multipart message in MIME format.
--===============1913075942==
Content-Type: multipart/alternative;
boundary="=_alternative 0065419D86257514_="

This is a multipart message in MIME format.
--=_alternative 0065419D86257514_=
Content-Type: text/plain; charset="US-ASCII"

>Yes. There are 2 hours each year when this formula is wrong.

I assume you're thinking of the switch from DST to CST and vice-versa,
yes? But since that change occurs at oh-dark-hundred (2:00AM), it's
already "today," and "yesterday" would be the same, wouldn't it? Or is it
a different pair of hours you're referring to?

More seriously, isn't this code subtracting a day twice?

>>>> my ($mday, $mon, $year) = (localtime(time() - 60 * 60 * 24) )[
3,4,5];
>>>> printf("%d/%02d/%02d\n", $year + 1900, $mon + 1, $mday - 1);

I would think that the first, subtracting from time() would be the correct
one--the one that would overcome changes in month, year, and time, while
the second, from $mday's value, is not just redundant, but at this point,
wrong, no? Not only that, it would introduce such curiosities as the
zero-th day of each month--the day before the first of a month.

On a picky note, wouldn't it be easier to just subtract 86400?

Deane Rothenmaier
Programmer/Analyst
Walgreens Corp.
224-542-5150

The chief cause of problems is solutions. - Eric Sevareid
--=_alternative 0065419D86257514_=
Content-Type: text/html; charset="US-ASCII"


<br><font size=2 face="sans-serif">></font><tt><font size=2>Yes.  There
are 2 hours each year when this formula is wrong.</font></tt>
<br>
<br><font size=2 face="sans-serif">I assume you're thinking of the switch
from DST to CST and vice-versa, yes?  But since that change occurs
at oh-dark-hundred (2:00AM), it's already "today," and "yesterday"
would be the same, wouldn't it? Or is it a different pair of hours you're
referring to?</font>
<br>
<br><font size=2 face="sans-serif">More seriously, isn't this code subtracting
a day twice?</font>
<br>
<br><tt><font size=2>>>>> my ($mday, $mon, $year) = (localtime(time()
- 60 * 60 * 24) )[ 3,4,5];<br>
>>>> printf("%d/%02d/%02d\n", $year + 1900, $mon
+ 1, $mday - 1);<br>
</font></tt>
<br><font size=2 face="sans-serif">I would think that the first, subtracting
from time() would be the correct one--the one that would overcome changes
in month, year, and time, while the second, from $mday's value, is not
just redundant, but at this point, wrong, no? Not only that, it would introduce
such curiosities as the zero-th day of each month--the day before the first
of a month. </font>
<br>
<br><font size=2 face="sans-serif">On a picky note, wouldn't it be easier
to just subtract 86400?</font>
<br>
<br><font size=2 face="sans-serif">Deane Rothenmaier<br>
Programmer/Analyst<br>
Walgreens Corp.<br>
224-542-5150<br>
<br>
The chief cause of problems is solutions. - Eric Sevareid</font>
--=_alternative 0065419D86257514_=--


--===============1913075942==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1913075942==--
Deane.Rothenmaier [ Mi, 03 Dezember 2008 19:25 ] [ ID #1979576 ]

Re: How to get yesterday's date in Perl

>Yes. There are 2 hours each year when this formula is wrong.

No, there are 2 hours each year where the 'time' fields wouldn't be exactly
24 hours earlier, but the date should be skookum

> More seriously, isn't this code subtracting a day twice?

>>>> my ($mday, $mon, $year) = (localtime(time() - 60 * 60 * 24) )[ 3,4,5];
>>>> printf("%d/%02d/%02d\n", $year + 1900, $mon + 1, $mday - 1);

> I would think that the first, subtracting from time() would be the
correct one--the one that would overcome changes in month, year, and time,
while the second, from $mday's value, is not just redundant, but at this
point, wrong, no?

Right, that's my typo-thinko - I was looking at trying to show the "$mday -
1" route and the attendant issues w/ first day of month etc. and then
compressed it to the better just sub the day's worth of seconds.

printf("%d/%02d/%02d\n", $year + 1900, $mon + 1, $mday);


> On a picky note, wouldn't it be easier to just subtract 86400?

Yes/no - 86400 isn't *that* meaningful to most normal folks (though I
should consider the audience) but 60*60*24 sort of documents where the
result comes from. Sort of.

a

-------------------
Andy Bach
Systems Mangler
Internet: andy_bach [at] wiwb.uscourts.gov
Voice: (608) 261-5738 Fax: 264-5932

When I retire, I'm going to spend my evenings by the fireplace, going
through those boxes. There are things in there that ought to be burned.
Richard Millhouse Nixon (Parade magazine)

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Andy_Bach [ Mi, 03 Dezember 2008 19:43 ] [ ID #1979577 ]

Re: How to get yesterday's date in Perl

--===============1726264785==
Content-Type: multipart/alternative; boundary=Apple-Mail-2-915220281


--Apple-Mail-2-915220281
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit

On Dec 3, 2008, at 10:25 , Deane.Rothenmaier [at] walgreens.com wrote:

>
> >Yes. There are 2 hours each year when this formula is wrong.
>
> I assume you're thinking of the switch from DST to CST and vice-
> versa, yes? But since that change occurs at oh-dark-hundred
> (2:00AM), it's already "today," and "yesterday" would be the same,
> wouldn't it? Or is it a different pair of hours you're referring to?

This occurs on the 23th hour in the fall and the 0th hour in the
spring. This program shows a brute force way to find these that might
convince you:

------------------------
$h = 60 * 60;
$end = time + 366 * 24 * $h;

for ($t = time; $t < $end; $t += 0.5 * $h) {
print scalar(localtime($t)), "\n" if day($t) eq day($t + $h) &&
day($t - 24 * $h) ne day($t + $h - 24 * $h);
}

sub day {
my($y, $m, $d) = (localtime shift)[5,4,3];
$y += 1900;
$m += 1;
return sprintf "%04d-%02d-%02d", $y, $m, $d;
}
------------------------

> More seriously, isn't this code subtracting a day twice?

True. That's a bug.

>
>
> >>>> my ($mday, $mon, $year) = (localtime(time() - 60 * 60 * 24) )
> [ 3,4,5];
> >>>> printf("%d/%02d/%02d\n", $year + 1900, $mon + 1, $mday - 1);
>
> I would think that the first, subtracting from time() would be the
> correct one--the one that would overcome changes in month, year, and
> time, while the second, from $mday's value, is not just redundant,
> but at this point, wrong, no? Not only that, it would introduce such
> curiosities as the zero-th day of each month--the day before the
> first of a month.
>
> On a picky note, wouldn't it be easier to just subtract 86400?

Easier to type perhaps but possibly not easier to most people to
recognize as correct. For Perl it does not matter as it will fold
constants at compile time and execute exactly the same code. Try:

perl -MO=Deparse -e "print time + 24 * 60 * 60"

--Gisle


--Apple-Mail-2-915220281
Content-Type: text/html;
charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

<html><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: space; =
-webkit-line-break: after-white-space; "><div><div>On Dec 3, 2008, at =
10:25 , <a =
href=3D"mailto:Deane.Rothenmaier [at] walgreens.com">Deane.Rothen maier [at] walgreen=
s.com</a> wrote:</div><br class=3D"Apple-interchange-newline"><blockquote =
type=3D"cite"><br><font size=3D"2" face=3D"sans-serif">></font><tt><font =
size=3D"2">Yes.  There are 2 hours each year when this formula is =
wrong.</font></tt> <br> <br><font size=3D"2" face=3D"sans-serif">I =
assume you're thinking of the switch from DST to CST and vice-versa, =
yes?  But since that change occurs at oh-dark-hundred (2:00AM), =
it's already "today," and "yesterday" would be the same, wouldn't it? Or =
is it a different pair of hours you're referring to?</font> =
</blockquote><div><br></div><div>This occurs on the 23th hour in the =
fall and the 0th hour in the spring.  This program shows a brute =
force way to find these that might convince =
you:</div><div><br></div><div>------------------------</div><div><div>$h&n=
bsp;=3D 60 * 60;</div><div>$end =3D time + 366 * 24 * =
$h;</div><div><br></div><div>for ($t =3D time; $t < $end; $t +=3D 0.5 =
* $h) {</div><div>    print scalar(localtime($t)), "\n" =
if day($t) eq day($t + $h) && day($t - 24 * $h) ne day($t + $h - =
24 * $h);</div><div>}</div><div><br></div><div>sub day =
{</div><div>    my($y, $m, $d) =3D (localtime =
shift)[5,4,3];</div><div>    $y +=3D =
1900;</div><div>    $m +=3D 1;</div><div>   =
 return sprintf "%04d-%02d-%02d", $y, $m, =
$d;</div><div>}</div></div><div>------------------------</div><br><blockqu=
ote type=3D"cite"><font size=3D"2" face=3D"sans-serif">More seriously, =
isn't this code subtracting a day =
twice?</font></blockquote><div><br></div><div>True.  That's a =
bug.</div><br><blockquote type=3D"cite"><br> <br><tt><font size=3D"2">>>>>=
my ($mday, $mon, $year) =3D (localtime(time() - 60 * 60 * 24) )[ =
3,4,5];<br> >>>> printf("%d/%02d/%02d\n", $year + 1900, $mon + 1, $mday =
- 1);<br> </font></tt> <br><font size=3D"2" face=3D"sans-serif">I would =
think that the first, subtracting from time() would be the correct =
one--the one that would overcome changes in month, year, and time, while =
the second, from $mday's value, is not just redundant, but at this =
point, wrong, no? Not only that, it would introduce such curiosities as =
the zero-th day of each month--the day before the first of a month. =
</font> <br> <br><font size=3D"2" face=3D"sans-serif">On a picky note, =
wouldn't it be easier to just subtract 86400?</font> =
</blockquote><div><br></div><div>Easier to type perhaps but possibly not =
easier to most people to recognize as correct.  For Perl it does =
not matter as it will fold constants at compile time and execute exactly =
the same code.  Try:</div><div><br></div><div>   =
 perl -MO=3DDeparse -e "print time + 24 * 60 * =
60"</div><div><br></div><div>--Gisle</div><div><br></div></div></body></ht=
ml>=

--Apple-Mail-2-915220281--

--===============1726264785==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1726264785==--
Gisle Aas [ Mi, 03 Dezember 2008 19:55 ] [ ID #1979578 ]

Re: How to get yesterday's date in Perl

> This occurs on the 23th hour in the fall and the 0th hour in the spring.
This program shows a brute force way
> to find these that might convince you [1].


Slick! I'm convinced. Hmm, so if you need it to be ever accurate (and want
to stay w/ localtime() you need to track changes in the DST field,
something like:
my ($isdst) = ( localtime() ) [8];

my ($mday, $mon, $year, $prev_isdst) = (localtime(time - 60 * 60 * 24) )[
3,4,5, 8];
printf("%d/%02d/%02d\n", $year + 1900, $mon + 1,
$isdst == $prev_isdst ? $mday
: $isdst > $prev_isdst ? (localtime($t - 60 * 60 * 23) )[ 3]
: (localtime($t - 60 * 60 * 25) )[ 3]
);

Probably won't convince you [2] but ....

a

[1]
$h = 60 * 60;
$end = time + 366 * 24 * $h;

for ($t = time; $t < $end; $t += 0.5 * $h) {
print scalar(localtime($t)), "\n" if day($t) eq day($t + $h) && day($t
- 24 * $h) ne day($t + $h - 24 * $h);
}

sub day {
my($y, $m, $d) = (localtime shift)[5,4,3];
$y += 1900;
$m += 1;
return sprintf "%04d-%02d-%02d", $y, $m, $d;
}

[2]
#!/usr/bin/perl
my $h = 60 * 60;
my $end = time + 366 * 24 * $h;

my $cur_isdst;
for (my $t = time; $t < $end; $t += 0.1 * $h) {
# 0 1 2 3 4 5 6 7 8
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t);

my ($mday, $mon, $year, $prev_isdst) = (localtime($t - 60 * 60 * 24) )[
3,4,5, 8];
printf("%d/%02d/%02d - cur: %s -24: %s -23: %s\n", $year + 1900, $mon + 1,
$isdst == $prev_isdst ? $mday
: $isdst > $prev_isdst ? (localtime($t - 60 * 60 * 23) )[ 3]
: (localtime($t - 60 * 60 * 25) )[ 3]
, scalar(localtime($t)) ,
day($t + $h) , day($t - 24 * $h), day($t + $h - 24 * $h) )
if day($t) eq day($t + $h) && day($t - 24 * $h) ne day($t + $h - 24 * $h);

# print scalar(localtime($t)), "\n" if day($t) eq day($t + $h) && day($t
- 24 * $h) ne day($t + $h - 24 * $h);
}

sub day {
my($y, $m, $d) = (localtime shift)[5,4,3];
$y += 1900;
$m += 1;
return sprintf "%04d-%02d-%02d", $y, $m, $d;
}
-------------------
Andy Bach
Systems Mangler
Internet: andy_bach [at] wiwb.uscourts.gov
Voice: (608) 261-5738 Fax: 264-5932

When I retire, I'm going to spend my evenings by the fireplace, going
through those boxes. There are things in there that ought to be burned.
Richard Millhouse Nixon (Parade magazine)

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Andy_Bach [ Mi, 03 Dezember 2008 20:46 ] [ ID #1979579 ]

RE: How to get yesterday's date in Perl

Andy_Bach [at] wiwb.uscourts.gov

>> > This occurs on the 23th hour in the fall and the 0th hour in the
>> > spring. This program shows a brute force way to find these that
>> > might convince you [1].
>> >
>> Slick! I'm convinced. Hmm, so if you need it to be ever accurate
>> (and want to stay w/ localtime() you need to track changes in the
>> DST field, something like:

I had a script that did something like this a while back and it ran every ten minutes. Caused no end of headaches that first time it came up to a Standard/Daylight Saving boundry. That's one of the best selling points of modules. These issues have usually been addressed so you don't have to worry about them. Just use Date::Calc and you can subtract one day. Easy as that.

--
Henry
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Henry Hartley [ Mi, 03 Dezember 2008 20:58 ] [ ID #1979580 ]

Re: How to get yesterday's date in Perl

> now I'm confused ...

my ($isdst) = ( localtime() ) [8];

my ($mday, $mon, $year, $prev_isdst) = (localtime(time - 60 * 60 * 24) )[
3,4,5, 8];
printf("%d/%02d/%02d\n", $year + 1900, $mon + 1,
$isdst == $prev_isdst ? $mday
: $isdst > $prev_isdst ? (localtime($t - 60 * 60 * 23) )[ 3]
: (localtime($t - 60 * 60 * 25) )[ 3]
);


The idea is, when DST starts/stops, it'll be different than 24 hours ago.
Depending upon which way it changed (the values are 1 and zero) we either
need to subtract 23 hours or 25 hours to be correct. I think.

Yes, this is why modules are a better idea. There are places where, alas,
you can't get those modules (for instance, our production box) or are
otherwise limited.

a
-------------------
Andy Bach
Systems Mangler
Internet: andy_bach [at] wiwb.uscourts.gov
Voice: (608) 261-5738 Fax: 264-5932

When I retire, I'm going to spend my evenings by the fireplace, going
through those boxes. There are things in there that ought to be burned.
Richard Millhouse Nixon (Parade magazine)

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Andy_Bach [ Mi, 03 Dezember 2008 21:20 ] [ ID #1979581 ]

Re: How to get yesterday's date in Perl

Andy_Bach [at] wiwb.uscourts.gov wrote:
>> This occurs on the 23th hour in the fall and the 0th hour in the spring.
> This program shows a brute force way
>> to find these that might convince you [1].
>
>
> Slick! I'm convinced. Hmm, so if you need it to be ever accurate (and want
> to stay w/ localtime() you need to track changes in the DST field,
> something like:
> my ($isdst) = ( localtime() ) [8];
>
> my ($mday, $mon, $year, $prev_isdst) = (localtime(time - 60 * 60 * 24) )[
> 3,4,5, 8];
> printf("%d/%02d/%02d\n", $year + 1900, $mon + 1,
> $isdst == $prev_isdst ? $mday
> : $isdst > $prev_isdst ? (localtime($t - 60 * 60 * 23) )[ 3]
> : (localtime($t - 60 * 60 * 25) )[ 3]
> );
>

If he's only interested in the date and not the time, I would think
just using localtime and changing the hour field to noon and using
Time::Local::timelocal to reverse back to epoch time would ensure
that your next localtime call would produce the correct date no
matter what the time is.

use Time::Local;
my [at] t = localtime; # convert epoch time for today to fields
$t[2] = 12; # change hour to noonish
my $time = timelocal ( [at] t); # convert back to epoch time
my [at] d = localtime $time; # [at] d now has the correct date for yesterday
# which you could also use with POSIX::strftime
# to format as you like
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Bill Luebkert [ Do, 04 Dezember 2008 00:49 ] [ ID #1979723 ]

RE: How to get yesterday's date in Perl

use Date::Calc qw(Today Add_Delta_Days);
$yesterday=3Dsprintf( "%04d/%02d/%02d", Add_Delta_Days( Today(), -1 ) );
print $yesterday

>>> 2008/12/03

Bour9

> -----Message d'origine-----
> De : activeperl-bounces [at] listserv.ActiveState.com =

> [mailto:activeperl-bounces [at] listserv.ActiveState.com] De la =

> part de Bill Luebkert
> Envoy=E9 : jeudi 4 d=E9cembre 2008 00:49
> =C0 : activeperl [at] listserv.activestate.com
> Objet : Re: How to get yesterday's date in Perl
> =

> Andy_Bach [at] wiwb.uscourts.gov wrote:
> >> This occurs on the 23th hour in the fall and the 0th hour =

> in the spring.
> > This program shows a brute force way
> >> to find these that might convince you [1].
> > =

> > =

> > Slick! I'm convinced. Hmm, so if you need it to be ever =

> accurate (and want
> > to stay w/ localtime() you need to track changes in the DST field,
> > something like:
> > my ($isdst) =3D ( localtime() ) [8];
> > =

> > my ($mday, $mon, $year, $prev_isdst) =3D (localtime(time - =

> 60 * 60 * 24) )[
> > 3,4,5, 8];
> > printf("%d/%02d/%02d\n", $year + 1900, $mon + 1,
> > $isdst =3D=3D $prev_isdst ? $mday
> > : $isdst > $prev_isdst ? (localtime($t - 60 * 60 * 23) )[ 3]
> > : (localtime($t - 60 * 60 * 25) )[ 3]
> > );
> > =

> =

> If he's only interested in the date and not the time, I would think
> just using localtime and changing the hour field to noon and using
> Time::Local::timelocal to reverse back to epoch time would ensure
> that your next localtime call would produce the correct date no
> matter what the time is.
> =

> use Time::Local;
> my [at] t =3D localtime; # convert epoch time for today to fields
> $t[2] =3D 12; # change hour to noonish
> my $time =3D timelocal ( [at] t); # convert back to epoch time
> my [at] d =3D localtime $time; # [at] d now has the correct date =

> for yesterday
> # which you could also use with =

> POSIX::strftime
> # to format as you like
> _______________________________________________
> ActivePerl mailing list
> ActivePerl [at] listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> =

> =

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
francois.bourgneuf [ Do, 04 Dezember 2008 08:32 ] [ ID #1979724 ]

RE: How to get yesterday's date in Perl

--===============0320514961==
Content-Type: multipart/alternative; boundary="0-418655998-1228464127=:21834"

--0-418655998-1228464127=:21834
Content-Type: text/plain; charset=us-ascii



Thank you to all who contributed to this discussion. Not only did this assist me in my problem, but I learnt a lot from the various contributions. Thanks so muchZilore



--0-418655998-1228464127=:21834
Content-Type: text/html; charset=us-ascii

<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><BR>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(16,16,255) 2px solid"><PRE>Thank you to all who contributed to this discussion. Not only did this assist me in my problem, but I learnt a lot from the various contributions. Thanks so much</PRE><PRE>Zilore</PRE></BLOCKQUOTE></td></tr></table><br>


--0-418655998-1228464127=:21834--

--===============0320514961==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0320514961==--
zilore mumba [ Fr, 05 Dezember 2008 09:02 ] [ ID #1979933 ]

escape some char

Hi,

Can someone pls shed me some light>>
I have a func --
sub get_formatStr {
my $formatStr = '"%xxxx#%yyyy#%zzzzz"';
return $formatStr;
}
where in above, %xxx, %yyy & %zzz are literals & all three being delimeted by '#' and the combination should always be enclosed by double quotes.
I have to use this string in a regex as below-
$cmd = "$prog -o $formatStr $queryStr"; ## first $cmd
But this cribs in cmd execution and o/p bangs!
However $cmd = "$prog -o \"%lxxxx#%yyyy#%zzzzz\" $queryStr"; ## second $cmd.
works fine & supplies expected o/p.no issues with $queryStr too. Now, problem arises when I use the first $cmd. Is there any way (built in funcs or tekniks) where in I can use the first $cmd and still get the good o/p as from second $cmd ?

TIA




_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
p sena [ Do, 11 Dezember 2008 12:06 ] [ ID #1980711 ]

Re: escape some char

Apologies, no regex being used here. Actu ally the question lies in why is the difference seen between when i use
$cmd_1 = "$prog -o $formatStr $queryStr";
and
$cmd_2 = "$prog -o \"%xxxx#%yyyy#%zzzzz\" $queryStr"; ## this is Ok.

In cmd 1 formatStr is equal to '"%xxxx#%yyyy#%zzzzz' (same as seen in cmd 2 except here dbl quotes exists as it is), and the single quotes are necessary.

Cheers.



--- On Thu, 12/11/08, Williamawalters [at] aol.com <Williamawalters [at] aol.com> wrote:

> From: Williamawalters [at] aol.com <Williamawalters [at] aol.com>
> Subject: Re: escape some char
> To: senapati2001 [at] yahoo.com
> Date: Thursday, December 11, 2008, 5:03 PM
> hi --
>
> In a message dated 12/11/2008 6:06:45 A.M. Eastern Standard
> Time,
> senapati2001 [at] yahoo.com writes:
>
> > Hi,
> >
> > Can someone pls shed me some light>>
> >
> > I have a func --
> >
> > sub get_formatStr {
> > my $formatStr =
> '"%xxxx#%yyyy#%zzzzz"';
> > return $formatStr;
> > }
> >
> > where in above, %xxx, %yyy & %zzz are literals
> > & all three being delimeted by '#'
> > and the combination should always be enclosed by
> double quotes.
> >
> > I have to use this string in a regex as below-
> > $cmd = "$prog -o $formatStr $queryStr";
> ## first $cmd
> > But this cribs in cmd execution and o/p bangs!
> > However
> > $cmd = "$prog -o
> \"%lxxxx#%yyyy#%zzzzz\" $queryStr";
> ## second $cmd.
> > works fine & supplies expected o/p.no issues with
> $queryStr too.
> > Now, problem arises when I use the first $cmd.
> > Is there any way (built in funcs or tekniks) where in
> I can
> > use the first $cmd and still get the good o/p as from
> second $cmd ?
> >
> > TIA
>
>
> i cannot see why the two strings should differ and hence
> why there should
> be any difference in their effect.
>
> i suspect you are not showing all relevant code.
>
> try this and see if the two strings are indeed exactly
> equal:
>
> my $fs = formatStr();
> my $cmd_1 = "$prog -o $fs $queryStr";
> my $cmd_2 = "$prog -o
> \"%xxxx#%yyyy#%zzzzz\" $queryStr";
> $cmd_1 eq $cmd_1 or die ":$cmd_1: not really
> :$cmd_2:";
>
> (btw -- although you do not show any such code, you mention
> using
> the format string returned from the function formatStr() in
> a regex.
> are you aware that the '#' character is a
> 'comment-to-end-of-line' when
> used in a regex with the regex //x switch?)
>
> hth -- bill walters
>
>
> **************Make your life easier with all your friends,
> email, and
> favorite sites in one place. Try it now.
> (http://www.aol.com/?optin=new-dp&icid=aolcom40vanity&ncid=e mlcntaolcom00000010)




_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
p sena [ Do, 11 Dezember 2008 12:56 ] [ ID #1980713 ]

RE: escape some char

p sena <> wrote:
> Hi,
>
> Can someone pls shed me some light>>
> I have a func --
> sub get_formatStr {
> my $formatStr = '"%xxxx#%yyyy#%zzzzz"';
> return $formatStr;
> }
> where in above, %xxx, %yyy & %zzz are literals & all three being
> delimeted by '#' and the combination should always be enclosed by
> double quotes.
> I have to use this string in a regex as below- $cmd = "$prog -o
> $formatStr $queryStr"; ## first $cmd But this cribs in cmd execution
> and o/p bangs!
> However $cmd = "$prog -o \"%lxxxx#%yyyy#%zzzzz\" $queryStr"; ##
> second $cmd.
> works fine & supplies expected o/p.no issues with $queryStr too. Now,
> problem arises when I use the first $cmd. Is there any way (built in
> funcs or tekniks) where in I can use the first $cmd and still get the
> good o/p as from second $cmd ?

Sorry, but I find it pretty difficult to work out what you are asking
from that. You refer to a "regex" but I see no sign of any regex, and
"this cribs in cmd execution and o/p bangs!" lost me completely. A
small, self contained example script (SSCE) that illustrated your
problem and that I could cut and paste, and run on my box might have
been more useful.

My best guess from reading your post several times is that you are
asking about quoting. If so, check out the quoting operators in 'perldoc
perlop', probably qq. If not, please feel free to try again, especially
with the SSCE.

HTH

--
Brian Raven

------------------------------------------------------------ -----------------------------------------------
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient or have received this e-mail in error, please advise the sender immediately by reply e-mail and delete this message and any attachments without retaining a copy. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.


_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Brian Raven [ Do, 11 Dezember 2008 13:02 ] [ ID #1980714 ]

Re: escape some char

p sena wrote:
> Hi,
>
> Can someone pls shed me some light>>
> I have a func --
> sub get_formatStr {
> my $formatStr = '"%xxxx#%yyyy#%zzzzz"';
> return $formatStr;
> }
> where in above, %xxx, %yyy & %zzz are literals & all three being delimeted by '#' and the combination should always be enclosed by double quotes.
> I have to use this string in a regex as below-
> $cmd = "$prog -o $formatStr $queryStr"; ## first $cmd
> But this cribs in cmd execution and o/p bangs!
> However $cmd = "$prog -o \"%lxxxx#%yyyy#%zzzzz\" $queryStr"; ## second $cmd.
> works fine & supplies expected o/p.no issues with $queryStr too. Now, problem arises when I use the first $cmd. Is there any way (built in funcs or tekniks) where in I can use the first $cmd and still get the good o/p as from second $cmd ?

Try: my $formatStr = '\\"%xxxx#%yyyy#%zzzzz\\"';
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Bill Luebkert [ Do, 11 Dezember 2008 13:08 ] [ ID #1980715 ]

Re: escape some char

--===============1756718378==
Content-Type: multipart/alternative;
boundary="-----------------------------1228997424"


-------------------------------1228997424
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit


In a message dated 12/11/2008 6:57:14 A.M. Eastern Standard Time,
senapati2001 [at] yahoo.com writes:

> the question lies in why is the difference seen
> between when i use
> $cmd_1 = "$prog -o $formatStr $queryStr";
> and
> $cmd_2 = "$prog -o \"%xxxx#%yyyy#%zzzzz\" $queryStr";


if $cmd_1 and $cmd_2 are indeed the same (i.e., if you include the
code fragment i listed in your code and the script does not die),
then any difference in behavior cannot be due to these strings
or to substrings of which they are composed.

the best thing to do is probably to start looking in some other
direction to find the reason for any differences in behavior.

hth -- bill


**************Make your life easier with all your friends, email, and
favorite sites in one place. Try it now.
(http://www.aol.com/?optin=new-dp&icid=aolcom40vanity&ncid=e mlcntaolcom00000010)

-------------------------------1228997424
Content-Type: text/html; charset="US-ASCII"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3DUS-ASCII">
<META content=3D"MSHTML 6.00.2800.1479" name=3DGENERATOR></HEAD>
<BODY id=3Drole_body style=3D"FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: =
Arial"
bottomMargin=3D7 leftMargin=3D7 topMargin=3D7 rightMargin=3D7><FONT id=3Drol=
e_document
face=3DArial color=3D#000000 size=3D2>
<DIV>
<DIV>In a message dated 12/11/2008 6:57:14 A.M. Eastern Standard Time,
senapati2001 [at] yahoo.com writes:</DIV>
<DIV> </DIV>
<DIV>> the question lies in why is the difference seen<BR>> between wh=
en i
use<BR>> $cmd_1 =3D "$prog -o $formatStr $queryStr";<BR>> and<BR>> =
$cmd_2
=3D "$prog -o \"%xxxx#%yyyy#%zzzzz\" $queryStr"; </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>if $cmd_1 and $cmd_2 are indeed the same (i.e., if you include the</DIV=
>
<DIV>code fragment i listed in your code and the script does not die),</DIV>
<DIV>then any difference in behavior cannot be due to these strings </DIV>
<DIV>or to substrings of which they are composed.   </DIV>
<DIV> </DIV>
<DIV>the best thing to do is probably to start looking in some other </DIV>
<DIV>direction to find the reason for any differences in behavior. &nbs=
p;
</DIV>
<DIV> </DIV>
<DIV>hth -- bill   </DIV>
<DIV> </DIV></DIV></FONT><BR><BR><BR><DIV CLASS=3D"aol_ad_footer" ID=
=3D"63b9f537f9e27ef62bb0a2805c2b99fb"><FONT style=3D"color: black; font: nor=
mal 10pt ARIAL, SAN-SERIF;"><HR style=3D"MARGIN-TOP: 10px">Make your life ea=
sier with all your friends, email, and favorite sites in one place. <a href=
=3D"http://www.aol.com/?optin=3Dnew-dp&icid=3Daolcom40vanity &ncid=3Demlcntao=
lcom00000010">Try it now</a>.</FONT></DIV></BODY></HTML>

-------------------------------1228997424--

--===============1756718378==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1756718378==--
Williamawalters [ Do, 11 Dezember 2008 13:10 ] [ ID #1980716 ]
Perl » gmane.comp.lang.perl.active-perl » How to get yesterday's date in Perl

Vorheriges Thema: Win32::Perms module for Active Perl version 5.8 (5.8.8, build 822)
Nächstes Thema: How to use perlapp with Tkx