chasethemetal Posted May 26, 2011 Share Posted May 26, 2011 So I have a database with a bunch of dates in it. In this format 05/15/2011. And this is how I get that out. $data = mysql_query("SELECT * FROM location ORDER BY id ASC") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { $date = $info['date']; }; echo "$date"; The resulted echo would be 05/26/2011 How do I get $date to echo out JUST 05? I'm trying to isolate the month. I think the method is using substrings, but I havent had any luck. Thanks any help would be great! Quote Link to comment https://forums.phpfreaks.com/topic/237573-substring-question/ Share on other sites More sharing options...
wildteen88 Posted May 26, 2011 Share Posted May 26, 2011 Use extract list($month, $day, $year) = explode('/', $row['date']); EDITED Quote Link to comment https://forums.phpfreaks.com/topic/237573-substring-question/#findComment-1220825 Share on other sites More sharing options...
dougjohnson Posted May 26, 2011 Share Posted May 26, 2011 OR - $justmonth = substr($date,0,2); Quote Link to comment https://forums.phpfreaks.com/topic/237573-substring-question/#findComment-1220830 Share on other sites More sharing options...
xyph Posted May 26, 2011 Share Posted May 26, 2011 Is your 'date' column a varchar or MySQL date column? If it's a date column, you can just use SELECT MONTH(`date`) as `date_month` FROM `location` ORDER BY `id` ASC Then use $info['date_month'] Quote Link to comment https://forums.phpfreaks.com/topic/237573-substring-question/#findComment-1220836 Share on other sites More sharing options...
chasethemetal Posted May 26, 2011 Author Share Posted May 26, 2011 Thanks!!! Works great. Quote Link to comment https://forums.phpfreaks.com/topic/237573-substring-question/#findComment-1220861 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.