CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Date Function

 



benchivers
Novice

Feb 14, 2002, 1:40 PM

Post #1 of 2 (301 views)
Date Function Can't Post

How do you make a date in the future using 'localtime()'?

e.g. using the server's current time and adding 180 days onto it , in date form.

Cheers,
Ben Chivers
Wheres the damn coffee? zzzZZZZZ!!!


fashimpaur
User / Moderator

Feb 14, 2002, 2:15 PM

Post #2 of 2 (299 views)
Re: [benchivers] Date Function [In reply to] Can't Post

Benchivers,

Here is a code example:


Code
  

$time
= time;
$time += 180 * 24 * 60 * 60;
$nowplus180days = localtime($time);
print ($nowplus180days);



time() returns the current time in seconds since epoch (Jan 1, 1970 at 00:00:00)
The second line adds the number of seconds desired to be added to it.
Storing the result of localtime in a scalar gets a nicely formatted date string.
Then we printed it. (Note, if you run this today, the date returned is an hour ahead [at least in US CST]. This is because the Daylight Savings Time is in effect
on that date and clocks are set ahead one hour. It is not an error.)

HTH,
Dennis

$a="c323745335d3221214b364d545".
"a362532582521254c3640504c3729".
"2f493759214b3635554c3040606a0",
print unpack"u*",pack "h*",$a,"\n\n";

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives