Problem with Saving and Displaying dates / times

Derived from the Blog tutorial -

this may be more of a PHP question rather than a Yii question -

(I also posted this up in the tutorial section - if it is not necessary there, then it can be deleted)

I am getting this error when I try to manage a blog post:

[font=courier]A non well formed numeric value encountered[/font]

And it is singling out this line as being the source of the error:

[font=courier]

00024:

<?php echo date('F j, Y',$post->createTime); ?>[/font]

Also worth noting:

When the date/time value is being submitted to the database, it is going in as all 0's - 0000-00-00 00:00:00

Any help or suggestions would be helpful.

Thanks.

Peace

It looks like your createTime field in your table is DateTime, but in the tutorial, it should be stored as a timestamp in a Integer field.

check the date function:

string date  ( string $format  [, int $timestamp  ] )

The param 2 should be int, not date.

Hi,

have you tried to use instead?

yo thanks for the help

that first option did the trick so i didnt test out that second one yet

thanks again -

I can't use Datetime fields with Yii? Are you sure?

Quote

It looks like your createTime field in your table is DateTime, but in the tutorial, it should be stored as a timestamp in a Integer field.

check the date function:

string date  ( string $format  [, int $timestamp  ] )

The param 2 should be int, not date.

this is what worked for me - setting up a integer field in MySQL and sending a timestamp to the database

But, storing dates as integers in the database, can you compare this dates?

Can you do a  "where post_date between '01-01-2009' and '31-01-2009' ", for example ?

Hi there,

I actually started a similar thread some days ago:

http://www.yiiframew…3.html#msg12973

I am also really interested in some good examples on how to handle both cases in mysql…

Rassy

You can use any column type you want. It depends on your personal preference. Just make sure, your attribute contains a valid representation:

You can also automate these conversions in beforeSave() or beforeValidate() in your AR.

Thanks to Mike for those clear examples

How about comparing dates of a table? Could you post some examples as well?

Quote

But, storing dates as integers in the database, can you compare this dates?

Can you do a  "where post_date between '01-01-2009' and '31-01-2009' ", for example ?

Thanks for your tipps

Rassy

See examples above how to adjust :start and :end for different column types.

Great stuff.

I think that it is better to use real date and datetime format just to have a better overview when looking at the data-base…

do you have this example in the date and datetime variation?

Thanks for your tipps

Rassy

Quote

do you have this example in the date and datetime variation?

This is left as a practice for you ;)