0

Good Afternoon,

I need to store a runners pace i.e 10 min 20 seconds.

At the moment i am storing as an INT in seconds and then displaying on a form using

<?= $form->field($model,'pace')->textInput(['value' => date('i:s', $model->pace)]) ?> 

Which works fine, But on save of the form i need to convert this back to an INT i tried the below but this gives me the datetime in int not just the seconds

public function beforeValidate(){
    if(!is_int($this->pace)){
        $this->pace = strtotime($this->pace);
    }
    return parent::beforeValidate();
}

Thank you

abilham
  • 37
  • 7
  • Hi! Try using that but remove the part you dont need in the date one : `date('Y-m-d H:i:sP', strtotime($value));` – MaxiGui Aug 13 '20 at 11:58
  • 2
    Does this answer your question? [Convert time in HH:MM:SS format to seconds only?](https://stackoverflow.com/questions/4834202/convert-time-in-hhmmss-format-to-seconds-only) – MaxiGui Aug 13 '20 at 12:06
  • @MaximeGUILHEM perfect! Thank you! – abilham Aug 13 '20 at 12:20

0 Answers0