Hi there,
sorry if this should be in the database section...I dont know
im trying to breakdown a mySQL date format into something I can pull the various bits out of.
After a long search (its hard when you arent sure exactly what you are searching for) I found this, which from the description, I hoped meant I had beensuccessful. Unfortunately it only kicks out the year for some reason. I looked at the sscanf and list documentation...but to no avail, hell I dont even really know what all the double Ds mean and why year has a four and all the rest have a 2 :-(

Although dont get me wrong I normally dont have anything against Double Ds LOL
Hopefully someone can help me.

$time = $myrow["time"];
list($year,$month,$date,$hour,$min,$sec) = sscanf($time,"%4dd%2dd%2dd%2dd%2dd%2dd");
echo "<br>Time is set to: ".$time;//returns 2004-10-15 14:40:00
echo "<br>Year is set to: ".$year;//returns 2004 as one would expect
echo "<br>month is".$month;
echo "<br>the date is".$date;
echo $hour;
echo $min;
echo $sec;

Thanks for reading!

    $time = time();
    
    echo '
    the current date/time is ' . date('Y-m-d h:i:s', $time) . '<br>
    breakdown:<br><br>
    year = ' . date('Y', $time) . '<br>
    month = ' . date('m', $time) . '<br>
    day = ' . date('d', $time) . '<br>
    hour = ' . date('h', $time) . '<br>
    minute = ' . date('i', $time) . '<br>
    second = ' . date('s', $time);
    

      Thanks a lot for answering, Ill give it a try when i get back to my proper computer!πŸ™‚

        That works great as you supplied it but unfortunately my $time is in this format already when i grab it from mySQL:
        2004-10-15 14:40:00

        Is there a way to convert it back to the large number that php can then convert or a different way?

        $time = time();
        echo "<br>Now the time is:".$time;
        //returns a huge number: 1098255172
        echo " which converts to ".date('Y-m-d h:i:s',$time)."<br>Breakdown:<br>
        Year=".date('Y',$time)."<br>
        Month =".date('m',$time)."<br>
        Day=".date('d',$time)."<br>
        hour=".date('h',$time)."<br>
        minute=".date('i',$time)."<br>
        seconds=".date('s',$time);
        

        Thanks again for your help.

          OK thanks!

          I think it would have been easiest if Id used a timestamp from the beginning instead of DATETIME or whatever its called.

          But nearly there now, wasnt as hard as last time I tried PHPing and mySQLing...either Im getting better or luckierπŸ˜ƒ

          The biggest advantage was installing it all with XAMPP, saved me messing around for hours on end and even after I had it installed not being able to get access to my database.

          thanks to you all for your help thus far

          FG

            Write a Reply...