Jump to content

format date coming from database


dazzathedrummer

Recommended Posts

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

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.