SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Ireland
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Turning day of the year number into a date

    Hi,

    the date() function in php has the facility to output a date as the day of the year using 'z'

    Does anyone know a quick way to reverse this? e.g. given 35, translate it to February 5th?

  2. #2
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Well, 35 would be March 5th

    This should work

    PHP Code:
     echo date("F j"mktime(00025)); 
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  3. #3
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess one way could be that you get a timestamp for the begining of the year, then add 35 * seconds-per-day to get the offset date.
    PHP Code:
    $first_day mktime(00011date('Y'));
    $offset_day $first_day 35 24 60 60;
    echo 
    date('Y-m-d'$offset_day); 
    Hope it works, cannot test it right now, since

    Btw The New Guy, 35th day is definitely in February .

  4. #4
    Put your best practices away. The New Guy's Avatar
    Join Date
    Sep 2002
    Location
    Canada
    Posts
    2,087
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Oh, I get what he wants to do. He wants the 5 to carry over. Ah.
    "A nerd who gets contacts
    and a trendy hair cut is still a nerd"

    - Stephen Colbert on Apple Users

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Ireland
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks dbevfat, that worked.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •