dazzathedrummer Posted March 18, 2010 Share Posted March 18, 2010 Hi, I need to extract the month number from a datetime field so that I can dynamically determine a graphic file name. i currently have this in my html table: <td VALIGN=top style=\"height:80; width:80;\"><img style=\"position:absolute; z-index:1;\" src=\"calpics/background.png\" height=\"79\" width=\"79\"> <img style=\"position:absolute; z-index:2;\" src=\"calpics/1.png\" height=\"79\" width=\"79\"> <img style=\"position:absolute; z-index:3;\" src=\"calpics/jan.png\" height=\"79\" width=\"79\"></td>". "<td>{$row['gl_date']}</td>". the top (left) TD builds the graphic, where I have "1.png" I'd like to determing the file name from the date. for a starting point, i'd like to know how to display {$row['gl_date']} as just the month number. Quote Link to comment https://forums.phpfreaks.com/topic/195681-format-date-coming-from-database/ Share on other sites More sharing options...
runnerjp Posted March 18, 2010 Share Posted March 18, 2010 how is the date stored in db? Quote Link to comment https://forums.phpfreaks.com/topic/195681-format-date-coming-from-database/#findComment-1028080 Share on other sites More sharing options...
trq Posted March 18, 2010 Share Posted March 18, 2010 DATE_FORMAT. Quote Link to comment https://forums.phpfreaks.com/topic/195681-format-date-coming-from-database/#findComment-1028083 Share on other sites More sharing options...
dazzathedrummer Posted March 18, 2010 Author Share Posted March 18, 2010 how is the date stored in db? it in datetime format - so for "2010-12-04 00:00:00" I need to extract "12" its more the sytax that i'm unsure of - i'm fairly new to php, but have been working with SQL for around eight years - just need a bit of guidance on how to make it work. Quote Link to comment https://forums.phpfreaks.com/topic/195681-format-date-coming-from-database/#findComment-1028093 Share on other sites More sharing options...
scvinodkumar Posted March 18, 2010 Share Posted March 18, 2010 hi you can get using query itself, like this select month(gl_date) from tablename; why u going for php, if u still need in php,use the below code, echo date('m',strtotime($row['gl_date'])); //with leader zeros, like, 03 or echo date('n',strtotime($row['gl_date'])); //without leader zeros, like, 03 Quote Link to comment https://forums.phpfreaks.com/topic/195681-format-date-coming-from-database/#findComment-1028096 Share on other sites More sharing options...
dazzathedrummer Posted March 18, 2010 Author Share Posted March 18, 2010 why u going for php thats a very good point!!! i'll give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/195681-format-date-coming-from-database/#findComment-1028100 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.