Results 1 to 8 of 8
  1. #1

    Date convirsion with php, is it possible ?

    Hi, I've just started php and am trying to convert a day number for example day 254 of year 2002 to format day of month of year. I have worked out how to make a program that soes this but it would be quite long and a pain to do, is there any function in PHP that would allow you to do this easily?

  2. #2
    Join Date
    Nov 2001
    Posts
    857
    If this isn't what you are looking for let me know...

    The following code outputs 09-11-02
    PHP Code:
    <?
    echo date ("m-d-y"mktime (0,0,0,1,254,2002));
    ?>
    If you would rather it output it in 09/11/02 format change the m-d-y to m/d/y

    Other than that I am pretty sure I understood you.

    Above the 1 is the month of January.
    The 245 is the days from day 0 of that month. The 2002 is the day.

    So basically mktime() returns the UNIX time stamp for 245 days after Jan 0, 2002. Then the date function converts it to m/d/y format...

    EDIT:
    If you would rather call a function instead of useing that format in each location you can do this.
    PHP Code:
    function return_date($day$year)
    {
      return 
    date("m/d/y"mktime (0,0,0,1,$day,$year));

    Then you can call it like:
    PHP Code:
    $my_date return_date('254''2002');
    echo 
    $my_date
    Regards,
    Michael
    Last edited by michaeln; 08-23-2002 at 04:43 PM.
    <?
    header("Location: http://www.hostevolve.com/");
    ?>

  3. #3
    Join Date
    Aug 2002
    Location
    Your House
    Posts
    3
    sounds pretty easy, you need a custom script for this.

  4. #4
    Thanks, exactly what I was looking for

  5. #5
    Join Date
    Aug 2002
    Location
    Plymouth
    Posts
    212
    Good you made a function. Apply it in a global file so that it can be called from any module.

  6. #6
    Sorry what global file?

  7. #7
    Join Date
    Nov 2001
    Posts
    857
    I think he simply means put it in a file named whatever you wish, lets say global.php.

    Then at the top of each of the scripts in your site you put:
    require("global.php");
    if the file is in the same directory as the global file or
    require("/path/to/global/file/global.php");
    if the file is not in the same directory.

    After that any variables or functions in global.php can now be used in the file you put the require statement in....
    <?
    header("Location: http://www.hostevolve.com/");
    ?>

  8. #8
    Oh thanks Now I understand, actually I only needed it once in the script so this wont be necessary

Posting Permissions

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