Yii Framework Forum: Problem with Saving and Displaying dates / times - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Problem with Saving and Displaying dates / times Rate Topic: -----

#1 User is offline   backgammon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-March 09

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

0

#2 User is offline   alex 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 23-April 09

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.
0

#3 User is offline   yoshi 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 28-February 09
  • Location:Germany

Posted 30 April 2009 - 08:39 AM

Hi,

have you tried to use instead?

0

#4 User is offline   backgammon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-March 09

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 -
0

#5 User is offline   ricardograna 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 375
  • Joined: 31-March 09
  • Location:Manaus/AM - Brazil

Posted 30 April 2009 - 12:18 PM

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

#6 User is offline   backgammon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 25-March 09

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.


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

#7 User is offline   ricardograna 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 375
  • Joined: 31-March 09
  • Location:Manaus/AM - Brazil

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 ?


0

#8 User is offline   RassyBaby 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 14-May 09

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
0

#9 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

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.

0

#10 User is offline   RassyBaby 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 14-May 09

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?

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
0

#11 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 31 May 2009 - 09:46 AM



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

#12 User is offline   RassyBaby 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 14-May 09

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
0

#13 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,013
  • Joined: 06-October 08
  • Location:Upper Palatinate

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 ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users