Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time format in laravel migration?

Tags:

php

time

laravel

I want to have an input, where you put a time in EU format like 12:00 or 21:34. (hh:mm) How do I do that?

Schema::create('posts', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title');
    $table->string('arena');
    $table->date("h,i"('beginn'));
    $table->timestamps();
});

This is what I have, but it's obviously wrong.

like image 847
Jonas Avatar asked Apr 19 '18 16:04

Jonas


People also ask

What is Time () in Laravel?

What is time () in Laravel? The time() function returns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

How is date defined in migration?

More Definitions of Migration Date Migration Date means the date on which the transfer of the Broadband Service will be effected, at which point the End-User's Broadband Service will commence being provided to the End-User by a different Communications Provider.

How do I change the data type in Laravel migration?

How to change data type of column in laravel 9 migration ? Step 1 : Install doctrine/dbal package. Step 2 : Generate migration file. Step 3 : Open generated migration file and update.


2 Answers

You can use $table->time('field_name');

Schema::create('posts', function (Blueprint $table) {
   $table->increments('id');
   $table->string('title');
   $table->string('arena');
   $table->time("begin");
   $table->timestamps();
});
like image 199
Khem Raj Regmi Avatar answered Sep 19 '22 19:09

Khem Raj Regmi


You could do this with Carbon, which is included in Laravel by default:

  1. Set a variable with the current time $date = Carbon::now()
  2. Set hour, for example 22 $date->hour = 22
  3. Set minutes, for example 54 $date->minutes = 54
  4. Finally, set $table->date($date)
like image 34
Melvin Hagberg Avatar answered Sep 18 '22 19:09

Melvin Hagberg