Forum Moderators: coopster

Message Too Old, No Replies

Formatting date in PHP

         

th1chsn

3:29 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



Hello, I was hoping that someone here can help me out with something. I have a web page where I am using PHP to substitute in values from a MySQL database.

Everything is working fine except that the date field in the database is not formatted in a readable format. When I call this field the date comes up as: 1060225148

That is how the field is in the database. Is there anyway that when I call it in the .php page that I can format it?

I am calling in my fields like this:
<?=$option_row['date_create']?>

Thanks is advance.

Randy

jatar_k

4:27 pm on Aug 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if that is an actual unix timestamp you could use
strftime [ca.php.net]

panic

6:26 pm on Aug 7, 2003 (gmt 0)

10+ Year Member



Use the date function ( [php.net...] ) to format the date as you see fit.

-panic

martekbiz

8:22 pm on Aug 9, 2003 (gmt 0)

10+ Year Member



use the timestamp column on MYSQL to store the date

then when you need to do some calculations on date you need to convert it into a Unix TimeStamp which would be done in a query like:

SELECT UNIX_TIMESTAMP(DATECOLUMNHERE) AS date from SOMETABLE

HTH

Aaron

th1chsn

9:15 pm on Aug 9, 2003 (gmt 0)

10+ Year Member



I am substituting the values from the database into the php page. I have been substituting values in like this and it works fine.

<?=$option_row['date_create']?>"

But when I try to format the above date I just get todays date:

<?=$option_row['date_create'] = date("F j, Y")?>"

Is there something wrong in the way I set it up?

martekbiz

9:32 pm on Aug 9, 2003 (gmt 0)

10+ Year Member



try:

echo date("F j, Y", $$option_row['date_create']);

Aaron

th1chsn

9:50 pm on Aug 9, 2003 (gmt 0)

10+ Year Member



Hi martekbiz,

I put <?echo date("F j, Y", $option_row['date_create'])?> and it worked perfectly!

Thanks for your help.

martekbiz

10:00 pm on Aug 9, 2003 (gmt 0)

10+ Year Member



:)

panic

3:44 am on Aug 10, 2003 (gmt 0)

10+ Year Member



gg

-panic