FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php HELP!!!





anhvta
i wan to create my web ,but now i have some problems with the date in php.some one know which function in php like TO_DAYS() in mysql ?help me pls....thx Embarassed
cafefort
Hi anhvta,

Here's how I do it:

Code:


//1) extracts from a timestamp : the day, the month and the year.

function _decomposerTS ($timestamp) {
            $timestamp = preg_replace("/[\D]/", '', $timestamp); ## Supprime tout ce qui n'est pas un chiffre

            if (strlen($timestamp) == 8) {
                $year = substr($timestamp, 0, 4);
                $month= substr($timestamp, 4, 2);
                $day  = substr($timestamp, 6, 2);
                return array('day'=>$day, 'month'=>$month, 'year'=>$year);
            }
            else {
               echo "<b>erreur</b> :: génération de tableau _beaktimestamp";
            }
        }


//2. Converts a timestamp to number of days like TO_DAYS()

function dateToDays ($timestamp) {
            list ($day, $month, $year) = array_values(decomposerTS($timestamp));

            $siecle = substr($year,0,2);
            $year = substr($year,2,2);

            if ($month > 2) {
                $month -= 3;
            }
            else {
                $month += 9;
                if ($year) {
                    $year--;
                }
                else {
                    $year = 99;
                    $siecle --;
                }
            }

            return ( floor((  146097 * $siecle)    /  4 ) +
                    floor(( 1461 * $year)        /  4 ) +
                    floor(( 153 * $month +  2) /  5 ) +
                        $day +  1721119);

        }


Hope this helps Smile
Jamatu
PHP- http://uk2.php.net/date
Code:
$today = date("D M d Y");


mySQL - CURDATE();
Code:
2006-03-31


mySQL - NOW();
Code:
2006-03-31 01:27:58
anhvta
thanks to cafefort,i will try your functions.my qestion is not so complicated,but i think your functions are very usefuls for my plan Razz
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.