Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthormsalhab
     

    I want to compute the time difference between 2 attributes with datetime datatype?

    and how to create an attribute with JUST 'time' type. I have tried to create it in the installer like this:

    'created_at time'

    but im still getting datetime datatype bye cheking the database.

    • CommentAuthormkhatib
     

    created_at is by default a Date object takes the default Formated date( date + time ), created_on is a date object in the format ( Y-m-d).

    Try using another name of your column, like creation_time for example and assign it the time type: creation_time time

    Remember, these are the akelos conventions:

    Date only: created_on, updated_on

    Date and time: created_at, updated_at

    Hope that will works.

    •  
      CommentAuthorriffed
     

    what mkhatib said...

    • CommentAuthormkhatib
     

    I Found that the types that akelos supports are:

    • integer|int, float, decimal,
    • string, text,
    • datetime|timestamp, date,
    • binary,
    • boolean

    In Addition, These Are the defaults conventions for akelos columns naming: * column_name | default setting * ---------------------------------------------------------------------------- * id | integer not null auto_increment primary_key * *_id,*_by | integer index * description,content,body | text * position | integer index * *_count | integer default 0 * lock_version | integer default 1 * *_at | datetime * *_on | date * is_*,has_*,do_*,does_*,are_* | boolean not null default 0 index * *somename | multilingual column => en_somename, es_somename * default | string

    • CommentAuthormkhatib
     

    Sorry if my answer was too confusing, what i am trying to say that when msalhab tried to do: created_at time

    It didn't work because the conventions overwrite his datatype to be datetime instead of time.

    and you can see from the last post, that time is not supported by akelos, try using timestamp.

    Hope this will be clear enough...

    • CommentAuthorThijs
     

    I want to compute the time difference between 2 attributes with datetime datatype?

    I've got a little function here. It takes the dates in date format ('YYYY-MM-DD') and will ignore the time part of a datetime

    function date_diff($begindatum,$einddatum){
       $beginseconden = gmmktime(0,0,0,substr($begindatum,5,2),substr($begindatum,8,2),substr($begindatum,0,4));
       $eindseconden = gmmktime(0,0,0,substr($einddatum,5,2),substr($einddatum,8,2),substr($einddatum,0,4));
       $totalsec = ($eindseconden - $beginseconden);
       $days = (floor($totalsec/86400) + 1);
       return $days;
    }
    
    • CommentAuthorThijs
     

    .. but you wanted to calculate time. (I should read better)

    er.. include the hour and minutes in the gmmktime statements.

    And then return $totalsec instead of days.

    •  
      CommentAuthorriffed
     

    You could store the time as an integer using time() which returns seconds since midnight 1970, then just subtract two numbers. http://us3.php.net/time

    • CommentAuthormkhatib
     

    Thanks guys for these information, but i've a question almost about the same topic, How can i bring down from the database all the posts that was posted within the last 24 hour? I've Tried this: // finding the date befor 24 hours $aDay = time() - (1 * 24 * 60 * 60); // trying to make the date looks like the database date $this->ca = date('Y-m-d H:i:s', $Aday) ; $this->Post->findAllBy('created_at > ?' , $last_24_hours)

    But it's not working... From the error message, the above is translated into:

    ... WHERE __owner.created_at = '2008-03-06 06:37:59' > '1' ...

    How I can get this working?

    • CommentAuthorThijs
     

    Shouldn't it be like this:

    (you didn't use $this->ca in your find)

    // finding the date befor 24 hours
    $aDay = time() - (1 * 24 * 60 * 60); 
    // trying to make the date looks like the database date
    $last_24_hours = date('Y-m-d H:i:s', $aDay) ; 
    $this->Post->findAllBy('created_at > ?' , $last_24_hours)
    
    • CommentAuthorThijs
     

    If you're still having problems with the query you might want to try:

    $this->Post->find('all',array("conditions" => "created_at > '".$last_24_hours."'"));
    
    • CommentAuthormkhatib
     

    Oh, my fault i just forgot to change the variable name, no the first one doesn't work, BUT fortunately the second one works like a charm! Thanks a lot thijs.