Day of the week finder - Programmers Heaven

Howdy, Stranger!

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

Categories

Day of the week finder

jandrewsjandrews Posts: 30Member
I'm creating an online calendar for my faculty at my high school to use, but in order to properly display a given month, I need to know on what day of the week the first of the month falls. How do I query what day of the week a given date falls on? Thanks.

James

Comments

  • tvientitvienti Posts: 230Member
    Use the strtotime and date functions. I'm not sure if that's the most efficient way, but it would work.

    strtotime let's to turn a string into a time represented as number of seconds since a fixed point. date accepts a number of seconds since the fixed point, and turns it into a string formatted however you want, according to the formatting string you input. So:

    [code]
    $seconds = strtotime('1 December, 2006');
    $day = date('l', $seconds);
    [/code]

    That will get you the day (Sunday - Saturday) that falls on the date 12/1/2006.

    T

    : I'm creating an online calendar for my faculty at my high school to use, but in order to properly display a given month, I need to know on what day of the week the first of the month falls. How do I query what day of the week a given date falls on? Thanks.
    :
    : James
    :

  • mac_doggiemac_doggie Posts: 488Member
    [b][red]This message was edited by mac_doggie at 2006-1-4 3:14:50[/red][/b][hr]
    or:
    [code]
    // mktime parameters:
    // hours, minutes, secods (don't need them so make them 0
    // then month, day, year
    // date("w") returns the day of the week 0 - 6 (0 beng sunday)
    $dayofweek = date("w", mktime(0,0,0,12,1,2006));

    [/code]

    also see: http://nl2.php.net/manual/en/function.date.php
    and: http://nl2.php.net/manual/en/function.mktime.php


    : Use the strtotime and date functions. I'm not sure if that's the most efficient way, but it would work.
    :
    : strtotime let's to turn a string into a time represented as number of seconds since a fixed point. date accepts a number of seconds since the fixed point, and turns it into a string formatted however you want, according to the formatting string you input. So:
    :
    : [code]
    : $seconds = strtotime('1 December, 2006');
    : $day = date('l', $seconds);
    : [/code]
    :
    : That will get you the day (Sunday - Saturday) that falls on the date 12/1/2006.
    :
    : T
    :
    : : I'm creating an online calendar for my faculty at my high school to use, but in order to properly display a given month, I need to know on what day of the week the first of the month falls. How do I query what day of the week a given date falls on? Thanks.
    : :
    : : James
    : :
    :
    :

    ;-)
    -mac-
    mailto:[email protected]
    the Netherlands...




Sign In or Register to comment.