how to get next day

B

Bob

Trying to calculate next date after user enters a date ?
can this be done with strftime ?

if user enters 1-Mar-2007, want to return 2-Mar-2007.
if user enters 5-Mar-2007, want to return 6-Mar-2007.

**************start of code ************************
use strict;
use warnings;
use POSIX 'strftime';
my $date1, date2;
print ("\n Enter the start date ex: (1-Mar-2006): ");
chomp($date1 = <STDIN>);

# calculate next day here

print ("You have entered a date of $date1 and the next day is: $date2 \n");
************** end of code ************************
 
J

Jürgen Exner

Bob said:
Trying to calculate next date after user enters a date ?

One way: You could take the answer to FAQ
"How do I find yesterday's date?"
and adapt it to your slightly different needs.

jue
 
U

usenet

Trying to calculate next date after user enters a date ?
can this be done with strftime ?

Probably. But I would use the DateCalc method of Date::Manip (and use
UnixDate to format it - even to format it to this d-Mmm-YYYY format,
which is awful, IMHO):

#!/usr/bin/perl
use strict; use warnings;
use Date::Manip;

my $date = '1-Mar-2006';
my $next_day = UnixDate(DateCalc( $date, '+ 1 day'), '%e-%b-%Y');
print "The day after $date is $next_day\n";
__END__
 
P

Paul Lalli

Trying to calculate next date after user enters a date ?
can this be done with strftime ?

if user enters 1-Mar-2007, want to return 2-Mar-2007.
if user enters 5-Mar-2007, want to return 6-Mar-2007.

**************start of code ************************
use strict;
use warnings;
use POSIX 'strftime';
my $date1, date2;
print ("\n Enter the start date ex: (1-Mar-2006): ");
chomp($date1 = <STDIN>);

# calculate next day here

print ("You have entered a date of $date1 and the next day is: $date2 \n");
************** end of code ************************


Use the module Date::parse, available from CPAN. This is one of the
many formats that it handles:

$ perl -MPOSIX -MDate::parse -le'
print "Enter date:";
chomp (my $date = <STDIN>);
my @time = strptime($date);
$time[3]++;
my $tomorrow = POSIX::strftime("%e-%b-%Y\n", @time);
$tomorrow =~ tr/ //d;
print $tomorrow;
'
Enter date:
31-Mar-2007
1-Apr-2007


(the tr/ //d portion of that is necessary because I don't see a
strftime option for "date of month, single digits aren't preceded by
anything")

Paul Lalli
 
B

Bob

Jürgen Exner said:
One way: You could take the answer to FAQ
"How do I find yesterday's date?"
and adapt it to your slightly different needs.

jue

Thanks for your info... perhaps you would help me with --

the following shows using today or NOW ....
what is the correct syntax for a different date -
like 1-Mar-2007.

use DateTime;
my $yesterday = DateTime->now->subtract( days => 1 );
print "Yesterday was $yesterday\n";

also use the "Date::Calc" module using its Today_and_Now
use Date::Calc qw( Today_and_Now Add_Delta_DHMS );
my @date_time = Add_Delta_DHMS( Today_and_Now(), -1, 0, 0, 0 );
print "@date\n";
 
M

Mothra

Bob said:
Thanks for your info... perhaps you would help me with --

the following shows using today or NOW ....
what is the correct syntax for a different date -
like 1-Mar-2007.

use DateTime;
my $yesterday = DateTime->now->subtract( days => 1 );
print "Yesterday was $yesterday\n";
use strict;
use warnings;
use DateTime;

my $date = DateTime->new( year => 2007,
month => 3,
day => 1
);
print $date->subtract(days =>1);

Hope this helps

Mothra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top