Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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);
HTH
-----
Of all the things I've lost in my life, its my mind I miss the most.


Comment on Re: How do you add dates to a certain user provided date?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-12-29 05:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls