arun4444 Posted June 16, 2007 Share Posted June 16, 2007 When i access the date Column in Mysql i get the following result "2007-06-16 14:02:49" What string function do i use to chop off the time, I have about 5 hours of Php experience, lol i am a total noob, please help ty arun Link to comment https://forums.phpfreaks.com/topic/55865-chop-sting/ Share on other sites More sharing options...
Silverado_NL Posted June 16, 2007 Share Posted June 16, 2007 if you create these date records yourself you should store em as UNIX Timestamps Here is a link to a short info site refering to this handy timestamp. http://www.tizag.com/phpT/phpdate.php If you dont create these timestamp you could chop it with the following function. <?php $datestring // lets say this is the variable holding the date like "2007-06-16 14:02:49". $time = substr($datestring, 11, ; // this will output the part of string starting from character 11 and counting 8 character long (14:02:49) part off the string $time // this contains "14:02:49" ?> Hope this helps you Link to comment https://forums.phpfreaks.com/topic/55865-chop-sting/#findComment-275995 Share on other sites More sharing options...
Psycho Posted June 16, 2007 Share Posted June 16, 2007 You would use a combinatin of strtotime() and date(). date() allows you to format a date and/or time in any manner you wish. But it requires a timestamp. strtotime() converts a database date/time to a timestamp: $time = "2007-06-16 14:02:49"; echo date("F j, Y", strtotime($time)); //Output: June 6, 2007 Also, here's a tutorial on the subject: http://www.phpfreaks.com/forums/index.php/topic,95430.0.html Link to comment https://forums.phpfreaks.com/topic/55865-chop-sting/#findComment-275998 Share on other sites More sharing options...
arun4444 Posted June 16, 2007 Author Share Posted June 16, 2007 Thank You very much it worked out, Link to comment https://forums.phpfreaks.com/topic/55865-chop-sting/#findComment-276005 Share on other sites More sharing options...
The Little Guy Posted June 16, 2007 Share Posted June 16, 2007 you could also do this: <?php $fulldate = '2007-06-16 14:02:49'; list($date, $time) = explode(" ",$fulldate); echo 'The date is: '.$date; echo 'The time is: '.$time; ?> Link to comment https://forums.phpfreaks.com/topic/55865-chop-sting/#findComment-276014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.