Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: How do you add dates to a certain user provided date?

by AcidHawk (Vicar)
on Mar 10, 2004 at 07:31 UTC ( #335379=note: print w/replies, xml ) Need Help??

in reply to How do you add dates to a certain user provided date?

I like the idea of converting to epoc time. And you can do this with core the Time::Local module.

You still face a challenge in that the year is not in ccyy format. So you need to work out is it 1904 or 2004 that you are dealing with.

Let's assume that you adddress this year problem and that based on your comment that this is not homework, look at this to convert the date from mm/dd/ccyy to epoc.

$date = "03/10/2004"; my @d = split/\\/, $date; # Second, Min , Hour , Day , Month, Year $epoc = timelocal(0, 0, 0, $d[1], $d[0], $d[2]);
You could then take $epoc and add ($num_of_days_to_add * 86400) which is the number of seconds in a day. All that's left to do is convert this new epoc number to a valid date.

($ss, $mm, $hh, $d, $mon, $yr) = localtime($epoc);
You can now build how you want to diaplsy your new date. Something like..
printf("NewDate: %02d/%02d/%04d\n", $mon+1, $d, $yr+1900);
Of all the things I've lost in my life, its my mind I miss the most.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://335379]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2021-01-27 23:23 GMT
Find Nodes?
    Voting Booth?