Forum Moderators: coopster

Message Too Old, No Replies

Date displaying incorrectly

Php Date problem

         

Tommybs

8:39 pm on Aug 24, 2007 (gmt 0)

10+ Year Member



Hi all,

Was wondering if anyone could help me. I have a small problem with dates appearing incorrectly and I don't know if anyone can see anything wrong.


$bm = "08"; // month of Aug
$by = "2007"; // year

$cm = date('m'); // current month
$cy = date('Y'); // Current Year

echo "<a href=\"page.php?m=$bm&y=$by\">".date('M',mktime(0,0,0,$bm,0,2007))."</a></p>";
echo "<br/>$cm";


Now I know the code above is only a very simple example but what I would expect it to output would be (As current month '$cm' is August at time of posting:
Aug
08

But for some reasone the Aug is appearing as Jul. The link reference to page.php comes up correctly i.e page.php?m=08

So basically what I'm saying is that the date of the month is appearing 1 month behind even though it is explictly set not to. Does anyone know why this would be happening? I am using php 5 (not too sure on exact version at moment) but this is just driving me crazy!

Any help would be appreciated.

jatar_k

8:58 pm on Aug 24, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it could be the day portion of the mktime function is set to 0

date('M',mktime(0,0,0,$bm,0,2007))

try setting it to 1

date('M',mktime(0,0,0,$bm,1,2007))

Tommybs

11:12 pm on Aug 31, 2007 (gmt 0)

10+ Year Member



Thanks that sorted it.

I would have replied sooner but i wasn't notified of a response even though I thought I ticked the box.

Oh well i'll double check that on another post or maybe I was being an idiot.

Thanks again