Forum Moderators: coopster

Message Too Old, No Replies

Timestamp for first of the month

         

itledi

5:57 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



I'm trying to make a date sensitive section of my script dynamic, not requiring me to enter in the month and date.

I'm trying to rewrite this code:

$month1=gmmktime(0,0,0,1,1,2008);

To this:

$month2=gmmktime(date("0,0,0,n,1,Y"));

However, I get the following outputs:

$month1=1199145600
$month2=1199235361 (with this one changing on reload)

Why is $month2 changing every second, and what can I do to make it stop?

mooger35

8:00 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



Your getting a Unix timestamp for a GMT date

I think what you want is:

$m = date('n');
$y = date('Y');
$month2=date("l, F j, Y",gmmktime(date("0,0,0,$m,1,$y")));

//returns "Tuesday, January 1, 2008"

mooger35

9:24 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



Ooops... left a date function in there

$month2=date("l, F j, Y",gmmktime("0,0,0,$m,1,$y"));

and if you are looking for the UNIX timestamp why not use strtotime instead.

$month2=strtotime("$y-$m-01");

// returns 1199163600

And then you can use that to convert to whatever format you want.

itledi

11:37 pm on Jan 3, 2008 (gmt 0)

10+ Year Member



Thank you, that makes a lot of sense and works great.