Results 1 to 8 of 8
-
08-23-2002, 03:40 PM #1Newbie
- Join Date
- Aug 2002
- Posts
- 7
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?
-
08-23-2002, 04:05 PM #2Web Hosting Master
- 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));
?>
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));
}
PHP Code:$my_date = return_date('254', '2002');
echo $my_date;
MichaelLast edited by michaeln; 08-23-2002 at 04:43 PM.
<?
header("Location: http://www.hostevolve.com/");
?>
-
08-23-2002, 04:27 PM #3New Member
- Join Date
- Aug 2002
- Location
- Your House
- Posts
- 3
sounds pretty easy, you need a custom script for this.
-
08-25-2002, 03:21 AM #4Newbie
- Join Date
- Aug 2002
- Posts
- 7
Thanks, exactly what I was looking for
-
08-25-2002, 10:28 AM #5Junior Guru
- 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.
-
08-25-2002, 04:05 PM #6Newbie
- Join Date
- Aug 2002
- Posts
- 7
Sorry what global file?
-
08-25-2002, 07:10 PM #7Web Hosting Master
- 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/");
?>
-
08-26-2002, 03:34 AM #8Newbie
- Join Date
- Aug 2002
- Posts
- 7
Oh thanks Now I understand, actually I only needed it once in the script so this wont be necessary