Miko Posted December 17, 2010 Share Posted December 17, 2010 Hi, I have in my DB a column with a timestamp as definition. Now I would like to have only the month and year of that column for further use in a form. How can I achieve that? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/221968-timestamp-from-db/ Share on other sites More sharing options...
MMDE Posted December 17, 2010 Share Posted December 17, 2010 $yearandmonth=substr($timestamp,0,7); $year=substr($timestamp,0,4); $month=substr($timestamp,5,2); Quote Link to comment https://forums.phpfreaks.com/topic/221968-timestamp-from-db/#findComment-1148603 Share on other sites More sharing options...
Pikachu2000 Posted December 17, 2010 Share Posted December 17, 2010 Or you can simply format it in the query string, instead of using some convoluted php code to format it. Assuming you're using MySQL: SELECT DATE_FORMAT(`timestamp_field`, '%M, %Y) AS stamp FROM `table` . . . etc. Quote Link to comment https://forums.phpfreaks.com/topic/221968-timestamp-from-db/#findComment-1148625 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.