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. 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? 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. 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. 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 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. 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
Archived
This topic is now archived and is closed to further replies.