beginner problem - using date("M", $i) where $i is an integer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bissatch@yahoo.co.uk

    beginner problem - using date("M", $i) where $i is an integer

    Hi,

    I am trying to use the following function:


    echo date("M", $i)


    to echo the date that the value of a variable, $i, represents (eg. 1 =
    Jan, 5 = May, 11 = Nov). Unfortunetely, it returns only Jan for any
    number which I assume is the 1970 date that this function returns when
    you screw up. I know that when I have the string value of '2005-05-01'
    in a variable, I have to convert it in the following function:


    echo date("M", strtotime($strd ate))


    Is something similar required when I use an integer? Thanks

    Burnsy

  • Ken Robinson

    #2
    Re: beginner problem - using date("M&qu ot;, $i) where $i is an integer



    bissatch@yahoo. co.uk wrote:[color=blue]
    > Hi,
    >
    > I am trying to use the following function:
    >
    >
    > echo date("M", $i)
    >
    >
    > to echo the date that the value of a variable, $i, represents (eg. 1 =
    > Jan, 5 = May, 11 = Nov). Unfortunetely, it returns only Jan for any
    > number which I assume is the 1970 date that this function returns when
    > you screw up. I know that when I have the string value of '2005-05-01'
    > in a variable, I have to convert it in the following function:[/color]

    The second parameter to the date() function is the number of seconds
    since 1970-01-01 (the UNIX beginning of time). To do what you want to
    do, use

    echo date("M",strtot ime('2005-'.$i.'-01'));

    Ken

    Comment

    • Chung Leong

      #3
      Re: beginner problem - using date("M&qu ot;, $i) where $i is an integer

      This is slightly more efficient, I think:

      echo date("M", mktime(0, 0, 0, $i));

      Comment

      Working...