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 Quote 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. Quote 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 ? Quote 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"; Quote 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 ? Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.