Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


getdate() always returning 0 for the day?

SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
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.


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);



  • mac_doggiemac_doggie Member Posts: 488
    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...

    mailto:[email protected]
    the Netherlands...
  • sadapressesadapresse Member Posts: 1
    tu vas trouver des solution ici soit sur

    des scripts gratuit pour les programmateur

    sur ce site
Sign In or Register to comment.