Convert getdate() to YYYY/MM/DD?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lagon666
    New Member
    • Jun 2009
    • 22

    #1

    Convert getdate() to YYYY/MM/DD?

    Is any solution to convert "1055901520 " to yyyy/mm/dd:

    Code:
    $date = getdate();
    print $date[0]; // return 1055901520
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    Look here.

    You will see that [0] is your timestamp (seconds since unix epoch).
    Code:
    // To get the year (yyyy) it's
    echo $date['year'];
    // Month (mm) is:
    echo $date['mon'];
    // Day (dd) is:
    echo $date['mday'];
    However, you should really look at the date() function as this is probably what you are after. To do your request would be:
    Code:
    $today = date("Y/m/d");
    echo $today;
    With the date() function you can put in a second parameter for inital timestamp if that's what you want. If you do not put an initial timestamp, it takes the current one. time() will get you a current timestamp.

    I have tried to tell you other ways to solve your problem, but you can use this if that's all you want:
    Code:
    $date = date("Y/m/d",getdate());
    print $date;

    Comment

    • Lagon666
      New Member
      • Jun 2009
      • 22

      #3
      Thank you

      But how can i convert timestamp (seconds since unix epoch) to date?
      (Converting a number to date)

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by Lagon666
        But how can i convert timestamp (seconds since unix epoch) to date?
        previous post, second paragraph.

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          Originally posted by TheServant
          With the date() function you can put in a second parameter for inital timestamp if that's what you want. If you do not put an initial timestamp, it takes the current one. time() will get you a current timestamp.

          I have tried to tell you other ways to solve your problem, but you can use this if that's all you want:
          Code:
          $date = date("Y/m/d",getdate());
          print $date;
          If you read the date() documentation you will see the first parameter is output format ("Y/m/d") and the second is your time stamp (1055901520 or getdate() or blank for current)...

          Comment

          Working...