Posts Tagged with time

Displaying 1-10 of 11 results.
Wiki: Yii2 behavior and beforeSave usage example without conflicts and errorswiki
posted by admin on February 22, 2017
Behaviors:

public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_dt',
'updatedAtAttribute' => 'updated_dt',
'value' => your datetime format value,//or remove row to default with UNIX TIMESTAMP
],
];
}

BeforeSave:

public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {

if ($this->isNewRecord){
//to do
}else{
//to do
}

return true;
}
return false;
}
Read more
Resolved: Yii2 Class 'app\models\TimestampBehavior' not found
posted by admin on February 21, 2017
I have User model and have behavior in model

<?php

namespace app\models;

use Yii;
use yii\base\NotSupportedException;
use yii\db\ActiveRecord;
use yii\helpers\Security;
use yii\web\IdentityInterface;
use app\helpers\Table;
use app\helpers\App;
/**
* This is the model class for table "tbl_user".
*
* @property integer $id
* @property string $username
* @property string $password
* @property string $email
* @property integer $role_id
* @property integer $user_id
* @property integer $status_id
* @property integer $created_dt
* @property integer $updated_dt
* @property integer $timezone_id
*/
class User extends \yii\db\ActiveRecord implements IdentityInterface
{
public $authKey;
public $accessToken;

/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%'.Table::$user.'}}';
}

public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => 'creation_time',
ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time',
],
'value' => function() { return App::datetime_now_unix(); },
],
];
}
. . .
}

Error

Class 'app\models\TimestampBehavior' not found
Read more
Resolved: Yii PHP DateTime UNIX TimeStamp NOW
posted by admin on February 20, 2017

$date = new DateTime();
return $date->format('U');

Error:

Class 'namespace\DateTime' not found
Read more
Resolved: PHP check time 00:00:00 from datetime
posted by admin on November 21, 2016
I have datetime from MySQL db in format Y:m:d H:i:s like

2014-11-02 02:04:05
2014-11-02 00:00:00
etc ...

I want to check, if time from datetime equal "00:00:00", then return or echo only date.
Result

2014-11-02 02:04:05
2014-11-02
Read more
Resolved: PHP datetime to russian user friendly format converting. Дата и время на русский на дружественный вид
posted by admin on October 12, 2016
I have datetime from databse MySQL, in format
2016-10-10 12:34:33

By PHP datetime formats I can have string like this
07 October 2016, 04:11, Friday

But I want the3 same output, but in russian
07 Октября 2016, 04:11, ПятницаRead more
Resolved: How to clear browser cache when re-uploading image with same filename, in php?
posted by admin on June 18, 2016
I have a listing of items, that also contains an image thumbnail. Sometimes I need to change the thumbnail image, but keep the filename the same. Is there a way to force the browser to download the newly uploaded image, instead of grabbing one from the browser cache?

This is very pertinent when people update their avatars, which causes confusion for some users, who keep seeing their old avatar, until they clear the browser cache, or restart the browser.Read more
Resolved: PHP filesize MB/KB conversion
posted by admin on June 18, 2016
How can I convert the output of PHP's filesize() function to a nice format with MegaBytes, KiloBytes etc?

like:
  • if the size is less than 1 MB, show the size in KB
  • if it's between 1 MB - 1 GB show it in MB
  • [*] if it's larger - in GBRead more
    Wiki: PHP strtotime() Functionwiki
    posted by admin on May 22, 2016
    Example
    Parse English textual datetimes into Unix timestamps:

    <?php
    echo(strtotime("now") . "
    ");
    echo(strtotime("3 October 2005") . "
    ");
    echo(strtotime("+5 hours") . "
    ");
    echo(strtotime("+1 week") . "
    ");
    echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "
    ");
    echo(strtotime("next Monday") . "
    ");
    echo(strtotime("last Sunday"));
    ?>

    Definition and Usage
    The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).

    Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.

    Note: Be aware of dates in the m/d/y or d-m-y formats; if the separator is a slash (/), then the American m/d/y is assumed. If the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. To avoid potential errors, you should YYYY-MM-DD dates or date_create_from_format() when possible.

    Syntax

    strtotime(time,now);


    Parameter Description
    time Required. Specifies a date/time string
    now Optional. Specifies the timestamp used as a base for the calculation of relative dates

    Technical Details
    Return Value: Returns a timestamp on success. FALSE on failure
    PHP Version: 4+
    Changelog: PHP 5.3.0: Now relative time formats such as this week, previous week, last week, and next week interprets a week period of Monday through Sunday, rather then a 7-day period relative to the current date/time
    PHP 5.3.0: Now 24:00 is a valid format
    PHP 5.2.7: In earlier versions, if requesting a given occurrence of a given weekday in a month where that weekday was the first day of the month it would incorrectly add one week to the returned timestamp. This has been corrected now
    PHP 5.1.0: Returns FALSE on failure (earlier versions returns -1), and issues E_STRICT and E_NOTICE time zone errors
    PHP 5.0.2: Now correctly computes "now" and other relative times from current time, not from today's midnight
    PHP 5.0.0: Allows microseconds (but they are ignored)Read more
    Resolved: PHP date or datetime to Yesterday, Today
    posted by admin on March 30, 2016
    In my social website, I want to convert datetimes in format, like
    Today
    YesterdayRead more
    Resolved: Yii cjuidatepicker not saving
    posted by admin on January 30, 2016
    I have this field in my _form.php

    <?php
    $this->widget('zii.widgets.jui.CJuiDatePicker',
    array(
    'model' => $model,
    'attribute' => 'founding',
    'language' => Yii::app()->language,
    'flat' => false, // tells the widget to show the calendar inline
    'options' => array(
    'showOn' => 'both', // also opens with a button
    'dateFormat' => 'yy-mm-dd', // format of "2012-12-25"
    'showOtherMonths' => true, // show dates in other months
    'selectOtherMonths' => true, // can seelect dates in other months
    'changeYear' => true, // can change year
    'changeMonth' => true, // can change month
    'yearRange' => '2000:2099', // range of year
    'minDate' => '2000-01-01', // minimum date
    'maxDate' => '2099-12-31', // maximum date
    'showButtonPanel' => true, // show button panel
    ),
    'htmlOptions' => array(
    'size' => '10',
    'maxlength' => '10',
    ),
    )
    );
    ?>


    Controller SAVE() saving NULL. I var_dump($model) and see NULL.
    Please help me to correct.Read more