smithmr8 Posted April 27, 2009 Share Posted April 27, 2009 Hi, I'm taking a "timestamp" value from a database, similar to this '2009-04-18 05:55:30'. I would like to know how I would be able to get the value for the 5/6th items (i.e. 04). Regards, Luke Link to comment https://forums.phpfreaks.com/topic/155907-using-certain-characters-from-a-string/ Share on other sites More sharing options...
premiso Posted April 27, 2009 Share Posted April 27, 2009 explode $time = '2009-04-18 05:55:30'; $time = explode("-", $time); $month = $time[1]; echo $month; One way to do it. But if you are just getting the data out for the specific purpose, you can use the MySQL Date functions and just pull the month out in the query instead of having to use PHP to parse the data. Link to comment https://forums.phpfreaks.com/topic/155907-using-certain-characters-from-a-string/#findComment-820691 Share on other sites More sharing options...
smithmr8 Posted April 27, 2009 Author Share Posted April 27, 2009 Cool, Thanks. Oh, how would I pull it just using the query ? Link to comment https://forums.phpfreaks.com/topic/155907-using-certain-characters-from-a-string/#findComment-820702 Share on other sites More sharing options...
premiso Posted April 27, 2009 Share Posted April 27, 2009 http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format $sql = "SELECT DATE_FORMAT(`datefield`, '%c') AS month FROM table_name"; Link to comment https://forums.phpfreaks.com/topic/155907-using-certain-characters-from-a-string/#findComment-820714 Share on other sites More sharing options...
Mchl Posted April 27, 2009 Share Posted April 27, 2009 SELECT MONTH(timestampField) AS monthStamp FROM table WHERE ? Link to comment https://forums.phpfreaks.com/topic/155907-using-certain-characters-from-a-string/#findComment-820715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.