Actually, what I want to do, is find out what day of the week the first of the month falls on. For example, October 2002 = the 1st was on a Tuesday. Here's the code I've been trying:

$thefirst=date("Ynj",strtotime("$y$m1"));
$dayFirst=date("D",strtotime($thefirst));

This is a calendar.

the variable "$y" is the 4 digit year the user is looking at, and the "$m" variable is the month. Those variables are either going to be the current month based on the timestamp, or a different month based on the querystring. I need to get the weekday for the first of whatever month it ends up on, so I can begin to lay out the calendar starting on the correct day.

I have this whole thing working in ASP (i know, ewwww) but I am going to run it on my own Apache server so I need to turn the whole thing into PHP.

    Well, you don't say what's going wrong, but turning a string into a timestamp and then into a string and then into a timestamp and then into a string seems a bit of a long-winded way of going about it. (I'm not sure that strtotime() would know what to do with "2002101" anyway - not that that's what you're sending it: you're probably sending it "2002", because the variable $m1 probably doesn't have a value.)

    If you've already got your $y and $m, then mktime(0, 0, 0 $m, 1, $y) is the first of the month. date('w',mktime(0,0,0,$m,1,$y)) will return 0 for Sunday, 1 for Monday, etc. (that might be easier to use for alignment purposes).

      I see. Like I said, this is being converted from ASP, so I am reading the ASP and trying to find equivalents in PHP (which I don't know very well yet).

      I see how your suggestion would be much simpler.

        Write a Reply...