mktime

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

mktime

Post by NiGHTFiRE »

Hey,
I have two columns in my database. one column is todays date:

Code: Select all

date('Y,m,d,H,i,s');
And then one to go one month ahead:

Code: Select all

mktime(0,0,0,date("m")+1, date("d"), date("Y"));
But it's not what i want,
For example when i ran it:

from date('Y,m,d,H,i,s) :
2006,07,30,17,56,41

thats like i want it. But with

mktime(0,0,0,date("m")+1, date("d"), date("Y"));

i get: 1156888800

I want that to be: 2006, 08, 30, 17,56,41

So it just gives the result one month ahead.
Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

pass the return from mktime() back to date() as the second argument.
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Code: Select all

$plus_start = date('Y,m,d,H,i,s');
$plus_stop = mktime(0,0,0,date("m")+1, date("d"), date("Y"));
$nyplus_stop = date($plus_stop);
That doesn't work. How should i do it?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

NiGHTFiRE wrote:

Code: Select all

$plus_start = date('Y,m,d,H,i,s');
$plus_stop = mktime(0,0,0,date("m")+1, date("d"), date("Y"));
$nyplus_stop = date($plus_stop);
That doesn't work. How should i do it?

Code: Select all

$nyplus_stop = date('Y,m,d,H,i,s', strtotime('+1 Month'));
You may want to look at the date() function, strtotime() and mktime() functions for how they handle their passed parameters and what they return.

EDIT | Actually made my post useful instead of error laiden garbage.
Last edited by RobertGonzalez on Sun Jul 30, 2006 12:35 pm, edited 1 time in total.
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Code: Select all

$nyplus_stop = date('Y,m,d,H,i,s', strtotime('+1 Month');
Gives me: Parse error: parse error, unexpected ';' in /srv/www/htdocs/test.php on line 10
bike5
Forum Newbie
Posts: 6
Joined: Mon Jul 03, 2006 7:31 pm

Post by bike5 »

Code: Select all

$nyplus_stop = date('Y,m,d,H,i,s', strtotime('+1 Month'));
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry about that. Seems I forgot a close parenthesis. :oops:
NiGHTFiRE
Forum Contributor
Posts: 156
Joined: Sun May 14, 2006 10:36 am
Location: Sweden

Post by NiGHTFiRE »

Oh, and i didn't even look for that :P
Thanks anyway :)
Post Reply