I need help writing a function for the following situation.
User inputs dates (as a single string) in the format of MM/DD/YYYY.
I need to convert this to YYYYXXX where XXX is the day of the year from 001 to 365.
As a seperate function, I need to convert YYYYXXX back to PHP native time format for conversion to MySQL format.
Any Ideas?!
Dates Problem ?
Moderator: General Moderators
you gotta tell it how many days per month...
what your doing is kinda similar to an add 1 hour type function
personally i would use a switch statement....
something along the lines of this:
hope that helps... check the syntax tho cos im not so good (but i done something similar in C++ so i know how to do it
)
what your doing is kinda similar to an add 1 hour type function
personally i would use a switch statement....
something along the lines of this:
Code: Select all
<?php
$month = substr($date, 0, 2);
$day = substr($date, 3, 2);//remebering to miss out the /
$year = substr($date, -4);
switch ($month)
{
case 1:
$temp = 31 + $day; //add 1 month to days into month
$output = ($year * 1000)+$temp;
echo "$output";
break;
case 2:
$temp = 59 + $day /* add jan + feb (if gonna be used for a couple of years include leap year provision
And So On*/
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Have a look at the calendar functions:
http://www.php.net/manual/en/ref.calendar.php
and the date and time functions:
http://www.php.net/manual/en/ref.datetime.php
Mac
http://www.php.net/manual/en/ref.calendar.php
and the date and time functions:
http://www.php.net/manual/en/ref.datetime.php
Mac