Forum Moderators: coopster

Message Too Old, No Replies

Simple PHP date script

Newbie - Pls help me re-format this date

         

Hollywood007

2:50 pm on Dec 30, 2005 (gmt 0)

10+ Year Member



The script I currently am using is this:

<?php
$no="4";
$prepare=mktime (0,0,0,date("m") ,date("d")+$no,date("Y"));
$future=strftime("%d-%m-%Y",$prepare);
echo "$no days from now is $future";
?>

... and when I run it, I get:

4 days from now is 03-01-2006

I want the line to read:

4 days from now is Tuesday, January 3rd

Can anyone assist me in changing the script to yield my desired output?

bmarx

5:04 am on Dec 31, 2005 (gmt 0)

10+ Year Member



Personally, i use a javascript date function on my site since it will execute on the users local machine and use the timestamp of the user, at least that is my understanding of it.

But it only looks like your date format is off a little bit. Instead of

$future=strftime("%d-%m-%Y",$prepare);

i would try

$future=strftime("%A, %B %d",$prepare);

source of suggestion: [us3.php.net...]

good luck!

IamStang

11:26 pm on Jan 2, 2006 (gmt 0)

10+ Year Member



Was just messing around with your code and came up with this.
<?php
$today = date("d-m-Y");
$no="4";
$advance = "+$no days";
$prepare = strtotime($advance);
$future = date("d-m-Y", $prepare);
echo "Today is $today. $no days from now is $future";
?>
Which produces
Today is 02-01-2006. 4 days from now is 06-01-2006

It gives the desired result. I even checked to make sure it took into account days near the end of the year. If anyone sees anything wrong with this, even I would appreciate a response.

Hope it helps!
IamStang