PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1845
Number of posts: 5013

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
getdate() always returning 0 for the day? Posted by Sephiroth on 28 Sept 2010 at 9:01 AM
Alright, I am trying to get the day of the week that the month started on so I can produce a PHP-based calendar for a site I am developing. For some reason however, "getdate()" is always forcing "wday" to zero. It's driving me insane because after hours of searching, I have come across several other calendars that use the exact same code that I use and they work. I don't get why this is happening, could somebody explain this, or is it another PHP anomaly?
$CurMonth = (date("n") - 1);
$CurYear = date("Y");
$Timestamp = mktime(0, 0, 0, $CurMonth, 1, $CurYear);
$MaxDay = date("t", $Timestamp);
$ThisMonth = getdate($Timestamp);
$StartDay = $ThisMonth['wday'];

Thanks for any help offered.

*EDIT*

I figured it out. Apparently the "mktime()" function in PHP doesn't adhere to regular coding practices, and the month range is 1-12, not 0-11. I modified the code as shown below and it works properly now.
$Timestamp = mktime(0, 0, 0, ($CurMonth + 1), 1, $CurYear);


-Sephiroth
Report
Re: getdate() always returning 0 for the day? Posted by mac_doggie on 4 Oct 2010 at 1:54 PM
To get the weekday of the first of the moth you could also use:
$startday = date("w", strtotime("01-".date("m-Y")));


Don't need to make a timestamp with mktime this way... Very handy function strtotime() it converts a string to a timestamp...


-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...
Report
Re: getdate() always returning 0 for the day? Posted by sadapresse on 9 Aug 2011 at 7:54 AM
tu vas trouver des solution ici soit sur

des scripts gratuit pour les programmateur

sur ce site

http://morescript.blogspot.com/
http://morescript.blogspot.com/
http://morescript.blogspot.com/



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.