Page 1 of 1
Problem with Saving and Displaying dates / times
#1
Posted 29 April 2009 - 08:34 PM
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:
A non well formed numeric value encountered
And it is singling out this line as being the source of the error:
00024:
<?php echo date('F j, Y',$post->createTime); ?>
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
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:
A non well formed numeric value encountered
And it is singling out this line as being the source of the error:
00024:
<?php echo date('F j, Y',$post->createTime); ?>
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
#2
Posted 29 April 2009 - 10:24 PM
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.
check the date function:
string date ( string $format [, int $timestamp ] )
The param 2 should be int, not date.
#4
Posted 30 April 2009 - 11:49 AM
yo thanks for the help
that first option did the trick so i didnt test out that second one yet
thanks again -
that first option did the trick so i didnt test out that second one yet
thanks again -
#6
Posted 30 April 2009 - 02:41 PM
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.
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
#7
Posted 29 May 2009 - 10:49 PM
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 ?
Can you do a "where post_date between '01-01-2009' and '31-01-2009' ", for example ?
#8
Posted 30 May 2009 - 12:20 PM
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
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
#9
Posted 30 May 2009 - 05:12 PM
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.
You can also automate these conversions in beforeSave() or beforeValidate() in your AR.
#10
Posted 31 May 2009 - 08:12 AM
Thanks to Mike for those clear examples
How about comparing dates of a table? Could you post some examples as well?
Thanks for your tipps
Rassy
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 ?
Can you do a "where post_date between '01-01-2009' and '31-01-2009' ", for example ?
Thanks for your tipps
Rassy
#11
Posted 31 May 2009 - 09:46 AM
See examples above how to adjust :start and :end for different column types.
#12
Posted 01 June 2009 - 03:31 AM
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
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
#13
Posted 01 June 2009 - 03:49 AM
Quote
do you have this example in the date and datetime variation?
This is left as a practice for you
Share this topic:
Page 1 of 1

Help

This topic is locked













