Using date, mktime and strotime

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
methos
Forum Newbie
Posts: 13
Joined: Sat Oct 21, 2006 8:31 am

Using date, mktime and strotime

Post by methos »

I'm trying to output day 1 of the current month but cannot quite grasp it. According to php.net for mktime: "Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time." so why doesn't it output the current month and year correctly???

Code: Select all

date("D, d M Y H:i:s" , mktime(9,30,45, date("M"),1, date("Y")))
date("D, d M Y H:i:s" , mktime(9,30,45,0,1,0))
date("D, d M Y H:i:s", strtotime("+0 month", strtotime("2006-11-01 09:30:45")))
These 3 output this:

Fri, 01 Dec 2006 09:30:45
Wed, 01 Dec 1999 09:30:45
Wed, 01 Nov 2006 09:30:45
Last edited by methos on Thu Mar 08, 2007 5:35 am, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try

Code: Select all

<?php
$date = date('D, d M Y H:i:s', mktime(0, 0, 0, date('n'), 1, date('Y')));
?>
Post Reply